Mnemonics and Palindromes 3

本文介绍了一个算法,用于生成由字母a、b、c组成的特定长度的字符串,这些字符串不包含任何回文子串,以此来创造极其复杂的名字。文章详细解释了如何确保生成的名字满足条件,并提供了一个具体的实现示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

F - Mnemonics and Palindromes 3
Time Limit: 1000MS Memory Limit: 65536K 64bit IO Format: %I64d& %I64u

[Submit [GoBack  [Status]

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  a b,and  c  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.

Input

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

Output

Output all different extremelycomplex names oflength  n  consisting of theletters  a b,and  c  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”.

Sample Input

input output
2
ab
ac
ba
bc
ca
cb

[Submit [GoBack  [Status]

Mnemonics <wbr>and <wbr>Palindromes <wbr>3 <wbr> <wbr>字母命名--(规律题)   Mnemonics <wbr>and <wbr>Palindromes <wbr>3 <wbr> <wbr>字母命名--(规律题)

输出共六行,每行都有规律。

#include<iostream>
using namespace std;
int main()
{
    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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值