赞
踩
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 3 appearing 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.
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
2
aa
3
bba
只要没有三个是回文的 直接输出aabbaabbaabb这个形式的 这个任意三个数没有回文 而且没有c
- #include <stdio.h>
- #include <string.h>
- #include <bits/stdc++.h>
- #define mod 1000000007
- #define ll long long
- using namespace std;
-
- int main()
- {
- int n;
- cin>>n;
- int k=1;
- for(int i=0;i<n;i++){
- if(i%2==0)k*=-1;
- if(k==1)printf("%c",'b');
- else printf("%c",'a');
- }
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。