-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathChef hates palindromes.cpp
63 lines (61 loc) · 982 Bytes
/
Chef hates palindromes.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<iostream>
using namespace std;
int main(){
int t,n,a;
cin>>t ;
while(t-->0){
cin>>n>>a;
if(a == 1){
cout<<n<<" ";
for(int i=0; i<n; i++){
cout<<" a ";//print
}
cout<<endl;
}
else if(a == 2){
if(n == 1)
cout<<"1 a"<<endl;
else if(n == 2)
cout<<"1 ab "<<endl;
else if(n == 3)
cout<<"2 aab "<<endl;
else if(n == 4)
cout<<"2 aabb "<<endl;
else if(n == 5)
cout<<"3 aabab"<<endl;
else if(n == 6)
cout<<"3 aaabbb"<<endl;
else if(n == 7)
cout<<"3 aaababb"<<endl;
else if(n == 8)
cout<<"3 aaababbb"<<endl;
else{
string s = "aabbabaabbab";
cout<<"4 ";
for(int i=0,j=0; i<n; i++){
cout<<s[j];
j++;
if(j == 12){
j=0;
}
}
cout<<endl;
}
}
else{
char ch = 'a';
int ctr = 0;
cout<<"1"<<" ";
for(int i=0; i<n; i++){
cout<<ch;
ch++;
ctr++;
if(ctr == a){
ctr = 0;
ch = 'a';
}
}
cout<<endl;
}
}
}