solution.cpp 916 字节
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
const int N = 1e5 + 5;
char str[N];
int main()
{   //字母只有26个,数大了就会超,剩下的还要分情况
    //	ios::sync_with_stdio(false);
    //	cin.tie(false);
    int n;
    cin >> n;
    int r = 0;
    while (r * (r + 1) / 2 < n)
        r++;
    r++;
    //	cout<<r<<endl;
    int t = (r - 1) * r / 2 - n;
    //	cout<<t<<endl;
    str[r - 1] = 'a';
    for (int i = r - 2; i >= 0; i--)
    {
        if (t > r / 2)
        {
            str[i] = str[i + 1];
            i--;
            str[i] = str[i + 1];
            i--;
            t -= 3;
        }
        else if (t > 0)
        {
            str[i] = str[i + 1];
            i--;
            t--;
        }
        if (i >= 0)
            str[i] = str[i + 1] + 1;
    }
    puts(str);
    return 0;
}