Mnemonics and Palindromes 3 - URAL 1737 水题

1737. Mnemonics and Palindromes 3

Time limit: 1.0 second
Memory limit: 64 MB
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  ab, 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  ab, 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”.

Sample

input output
2
ab
ac
ba
bc
ca
cb


思路:就是让abc,acb,bac,bca,cab,cba循环下去到n的长度。注意四n=1的情况。

AC代码如下:

#include<cstdio>
#include<cstring>
using namespace std;
char s[7][20010];
int main()
{ int n,i,j,k;
  s[1][1]='a';s[1][2]='b';s[1][3]='c';
  s[2][1]='a';s[2][2]='c';s[2][3]='b';
  s[3][1]='b';s[3][2]='a';s[3][3]='c';
  s[4][1]='b';s[4][2]='c';s[4][3]='a';
  s[5][1]='c';s[5][2]='a';s[5][3]='b';
  s[6][1]='c';s[6][2]='b';s[6][3]='a';
  scanf("%d",&n);
  for(i=1;i<=6;i++)
  { for(j=4;j<=n;j++)
     s[i][j]=s[i][j-3];
  }
  if(n==1)
  printf("a\nb\nc\n");
  else if(n<=16666)
   for(i=1;i<=6;i++)
   { for(j=1;j<=n;j++)
      printf("%c",s[i][j]);
     printf("\n");
   }
  else
   printf("TOO LONG\n");
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值