繁华模拟赛 vicent的字符串

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 200005;
int n,k,a[maxn];
char cmd;
int main(){
    freopen("str.in","r",stdin);
    freopen("str.out","w",stdout);
    ios::sync_with_stdio(false);
    cin>>n>>k;
    if(k == 1 && n == 1){
        cout<<"a";
        return 0;
    } 
    if(k == 1 || k > n){
        cout<<-1;
        return 0;
    }
    int cnt = n;
    for(int i = k;i >= 3;i--){
        a[cnt] = i;
        cnt--;
    }
    for(int i = 1;i <= cnt;i++){
        if(i&1) a[i] = 1;
        else a[i] = 2;
    }
    for(int i = 1;i <= n;i++){
        cmd = 'a' - 1 + a[i];
        cout<<cmd;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/hyfer/p/5904451.html