#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define all(a) a.begin(),a.end()
#define v vector
#define pb push_back
#define LB lower_bound
void wyp(int n){
if(n>0) cout << 'A';
for(int i=0;i<n-2;i++) cout << 'P';
if(n>1) cout << 'A';
}
void rozw(int n, int k){
if(k<4){
if(k==3 and n==7){
for(int i=0;i<k-1;i++) cout << 'P';
cout << "AP";
for(int i=0;i<k;i++) cout << 'A';
cout << '\n';
return;
}
if(k==3 and n==8){
for(int i=0;i<k;i++) cout << 'P';
cout << "AP";
for(int i=0;i<k;i++) cout << 'A';
cout << '\n';
return;
}
if(k*2<n){
cout << "NIE\n";
return;
}
for(int i=0;i<n;i++){
if(i<k) cout << 'A';
else cout << 'P';
}
cout << '\n';
return;
}
int pom=n/(k+2);
for(int i=0;i<pom;i++){
wyp(k);
cout << "PA";
}
int x=(n-(pom*(k+2)));
if(x) cout << 'A';
for(int i=0;i<min(k-2,x-1);i++) cout << 'P';
if(x>=k) cout << 'A';
if(x+1>=k+2) cout << 'P';
cout << '\n';
return;
}
int main(){ios_base::sync_with_stdio(0);cin.tie(0);
int n, x, y;
cin >> n;
for(int i=0;i<n;i++){
cin >> x >> y;
rozw(x,y);
}
return 0;
}
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 64 | #include <bits/stdc++.h> using namespace std; #define LL long long #define all(a) a.begin(),a.end() #define v vector #define pb push_back #define LB lower_bound void wyp(int n){ if(n>0) cout << 'A'; for(int i=0;i<n-2;i++) cout << 'P'; if(n>1) cout << 'A'; } void rozw(int n, int k){ if(k<4){ if(k==3 and n==7){ for(int i=0;i<k-1;i++) cout << 'P'; cout << "AP"; for(int i=0;i<k;i++) cout << 'A'; cout << '\n'; return; } if(k==3 and n==8){ for(int i=0;i<k;i++) cout << 'P'; cout << "AP"; for(int i=0;i<k;i++) cout << 'A'; cout << '\n'; return; } if(k*2<n){ cout << "NIE\n"; return; } for(int i=0;i<n;i++){ if(i<k) cout << 'A'; else cout << 'P'; } cout << '\n'; return; } int pom=n/(k+2); for(int i=0;i<pom;i++){ wyp(k); cout << "PA"; } int x=(n-(pom*(k+2))); if(x) cout << 'A'; for(int i=0;i<min(k-2,x-1);i++) cout << 'P'; if(x>=k) cout << 'A'; if(x+1>=k+2) cout << 'P'; cout << '\n'; return; } int main(){ios_base::sync_with_stdio(0);cin.tie(0); int n, x, y; cin >> n; for(int i=0;i<n;i++){ cin >> x >> y; rozw(x,y); } return 0; } |
English