#include <iostream>
using namespace std;
// Nearly Lucky Number
int main()
{
//如果小于=4,就直接输出
//如果大于4,
//
//
//这应该叫贪心?
int n; cin >> n;
if (n <= 4) {
for (int i = 0; i < n; i++) cout << (char) ('a' + i);
return 0;
}
char* c = new char[n] ;
int j = 0;
for (int i = 0; i < n; i++) {
if (i - 4 >= 0 && i - 7 >= 0) {
if (c[i - 4] < c[i - 7] && c[i - 1] != c[i - 4]) c[i] = c[i - 4];//i-4小,与i-1不相同
else if (c[i - 7] < c[i-4]&& c[i - 7] != c[i - 3]) { c[i] = c[i - 7]; }//i-7小, i-7与i-3不相同
else if (c[i - 4] != c[i - 1]) c[i] = c[i - 4];//i-4大,但可以
else if (c[i - 7] != c[i - 3]) c[i] = c[i - 7];//i-7大,但可以
}
else if (i - 4 >= 0 && i - 7 < 0) c[i] = c[i - 4];
else {
c[i] =(char) ( 'a' + j);
j++;
}
}
for (int i = 0; i < n; i++) cout << c[i];
return 0;
}
Petya recently learned to determine whether a string of lowercase Latin letters is lucky. For each individual letter all its positions in the string are written out in the increasing order. This results in 26 lists of numbers; some of them can be empty. A string is considered lucky if and only if in each list the absolute difference of any two adjacent numbers is a lucky number.