欢迎使用CSDN-markdown编辑器

GYM - 100812K Might and Magic (构造字符串)

I was walking upstairs directly to the tower of Dragon, and step by step skies became closer and closer. I entered into a small room lighted by dozens of candles. Dragon sat at a big wooden table. The blood of his men was still flowing from my drawn sword right onto the parquet floor, answering all possible questions in advance.

Dragon made a bet on magic. He grabbed a scroll and started to write a spell on it. A spell was a string consisting of only lowercase Latin letters «a», «b» and «c», which should have been written on a special magic scroll consequently, one letter after another, from left to right. Whenever the written string ended with two non-empty identical consecutive substrings, the spell corresponding to that string immediately triggered and the scroll collapsed. It should be noted that not every string, even if it ended with two non-empty identical consecutive substrings, was a spell. For example, a string «bacabacbacabacabcab» is not a spell, because at the moment when its prefix «bacabacbac» is written on a scroll, the corresponding spell triggers and the scroll disappears, leaving no way to add something else.

It was known that the longer spells were stronger. Dragon was nervously writing one symbol after another, trying to create a spell strong enough to destroy me. Through the mask of indifference I saw fear and confusion in his eyes. What string are you trying to write down, Dragon? You’d better hurry. It’s impolite to make a guest wait.

Input
There is only one test in this problem. In its only line the only integer 100000 is written.

Output
Output a string of length 105 that is not a spell and that can be written on a scroll to the very end.

Example
Input
7
Output
abacaba
Note
In the sample a correct string of length 7 is presented, even though there is no such test in the judging system.

如何在未知数目的字串里填上abc三个字母,还不会有重复段出现

#include<iostream>
#include<queue>
using namespace std;
typedef long long int ll;

int n;
char ans[100005];
int main()
{
    cin>>n;
    ans[0]='a';
    ans[1]='b';
    ans[2]='c';
    for(int i=3;i<n;i++)
     {
        for(int j=0;j<3;j++)
        {
            if(ans[i/2]!='a'+j&&ans[i-1]!='a'+j)
            {
                ans[i]='a'+j;
            }
        }
     }
     cout<<ans<<endl;


    return 0;
} 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值