您的位置:首页 > 其它

G - Mnemonics and Palindromes 3 URAL - 1737(回文)

2017-12-06 10:52 381 查看
As you remember, when Vasechkin was preparing a problem for the latest student contest, he spent a lot of time trying to invent an unusual and complex name for this problem. The name that Vasechkin had invented was so complex that none of the participants of that contest even started reading the statement of his problem.
After the contest, Chairman of the program committee announced that he refused to take part in the preparation of contests as long as such inappropriate people as Vasechkin worked on the program committee. That was how Vasechkin became the new Chairman of the program committee, and now he is preparing the next programming contest.
Vasechkin has decided that this time the names of all the problems will consist of the letters a, b, and c only and the length of each name will be equal to n. In addition, the names must be extremely complex. A name is extremely complex if none of its substrings consisting of at least two symbols is a palindrome. Help Vasechkin find all extremely complex names for the problems of the contest.


Input

The only input line contains the integer n (1 ≤ n ≤ 20000).

Output

Output all different extremely complex names of length n consisting of the letters a, b, and c only. The names should be given in the alphabetical order, one per line. If the total length of the names exceeds 100000 letters, output the only line “TOO LONG”.

Example

input

2


output

ab
ac
ba
bc
ca
cb


题意:给出字符串的长度,字符串仅由a,b,c组成,字符串内不能含有回文串,其中aa,bb,cc的也算回文,问字符串有多少可能。假如字符串一开始为abc为了不组成回文则下一个只能一次放a,b,c则该长度为n的字符串就前三个不停循环,总共有六种情况:abc,acb,bca,bac,cab,cba,这六种情况循环。

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char a[10010][4] = {"abc","acb","bac","bca","cab","cba"};
int n,i,j;
scanf("%d",&n);
if(n == 1) printf("a\nb\nc\n");
else if(n*6 > 100000) printf("TOO LONG\n");
else
{
for(i=0;i<6;i++)
{
for(j=0;j<n;j++)
{
printf("%c",a[i][j%3]);
}
printf("\n");
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: