Codeforces 805 B

来源:互联网 发布:收入词典的网络词语 编辑:程序博客网 时间:2024/05/20 19:49
B. 3-palindrome
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.

He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.

Input

The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.

Output

Print the string that satisfies all the constraints.

If there are multiple answers, print any of them.

Examples
input
2
output
aa
input
3
output
bba
Note

palindrome is a sequence of characters which reads the same backward and forward.

题意:就是给你一个字符串长度,然后要求不能出现长度为3的回文子串。使用c尽可能少。
思路:直接由2个字母就可以构成题目要求的了,也就是形如aabbaabbaabbaa;bbaabbaabbaa这种即可。
代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int num=0;
        for(int i=0,tem=1;i<n;i++,tem++)
        {
            if(tem>=1&&tem<=2)
            {
                printf("%c",'a');
            }
            if(tem>2&&tem<=4)
            {
                printf("%c",'b');
                if(tem==4) tem=0;
            }
        }
        puts("");
    }
    return 0;
}

0 0
原创粉丝点击