F - Mnemonics and Palindromes 3
Time Limit: | Memory Limit: | 64bit IO Format: |
Description
As you remember, when Vasechkin waspreparing a problem for the latest student contest, he spent a lotof time trying to invent an unusual and complex name for thisproblem. The name that Vasechkin had invented was so complex thatnone of the participants of that contest even started reading thestatement of his problem.
After the contest, Chairman of theprogram committee announced that he refused to take part in thepreparation of contests as long as such inappropriate people asVasechkin worked on the program committee. That was how Vasechkinbecame the new Chairman of the program committee, and now he ispreparing the next programming contest.
Vasechkin has decided that thistime the names of all the problems will consist of theletters
only and thelength of each name will be equal to
n. Inaddition, the names must be
extremelycomplex. A name is extremely complex if none of its substringsconsisting of at least two symbols is a palindrome. Help Vasechkinfind all extremely complex names for the problems of thecontest.
a
,
b
,and
c
Input
The only input line contains theinteger
n
(1≤
n
≤ 20000).
Output
Output all different extremelycomplex names oflength
n
consisting of theletters
only. Thenames should be given in the alphabetical order, one per line. Ifthe total length of the names exceeds 100000 letters, output theonly line “TOO LONG”.
a
,
b
,and
c
Sample Input
input | output |
---|---|
2 | ab ac ba bc ca cb |


输出共六行,每行都有规律。
#include<iostream>
int n,i;
while(cin>>n)
chara[3]={'a','b','c'};
if(n*6>100000){cout<<"TOO LONG"<< endl; return 0;}
if(n==1){ cout<< "a\nb\nc\n"; return 0;}
for(i=0;i<n;i++)
{
cout<<a[i%3];
}
cout<< endl;
a[0]='a';a[1]='c';a[2]='b';
for(i=0;i<n;i++)
{
cout<<a[i%3];
}
cout<<endl;
a[0]='b'; a[1]='a';a[2]='c';
for( i=0;i<n; i++)
{
cout<<a[i%3];
}
cout<<endl;
a[0]='b'; a[1]='c';a[2]='a';
for(i=0;i<n;i++)
{
cout<<a[i%3];
}
cout<<endl;
a[0]='c'; a[1]='a';a[2]='b';
for(i=0;i<n; i++)
{
cout<<a[i%3];
}
cout<<endl;
a[0]='c'; a[1]='b';a[2]='a';
for(i=0;i<n;i++)
{
cout<<a[i%3];
}
cout<<endl;
return 0;
using namespace std;
int main()
{
{
}
}