#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main() {
ios_base::sync_with_stdio(false);
string imie;
int n, t;
cin>>imie>>n>>t;
while(t--){
string kod;
cin>>kod;
string ans;
if(kod.size()%2==1)kod+="0";
for(unsigned i=0; i<kod.size(); i+=2){
string moje;
if(kod[i]==kod[i+1] && kod[i]=='1'){
cout<<"P"<<endl;
//if(imie[0]=='B')cerr<<"P"<<endl;
moje="P";
}else if(kod[i]==kod[i+1] && kod[i] =='0'){
cout<<"K"<<endl;
//if(imie[0]=='B')cerr<<"K"<<endl;
moje="K";
}else{
cout<<"N"<<endl;
//if(imie[0]=='B')cerr<<"N"<<endl;
moje="N";
}
string a;
cin>>a;
if(a==moje){
if(a=="P"){
ans+="11";
}else if(a=="K"){
ans+="00";
}else{
if(kod[i]=='1' && kod[i+1]=='0'){
cout<<"P"<<endl;
//if(imie[0]=='B')cerr<<"P"<<endl;
string b;
cin>>b;
if(b=="P"){
ans+="10";
}else{
ans+="01";
cout<<"K"<<endl;
//if(imie[0]=='B')cerr<<"K"<<endl;
cin>>b;
}
}
if(kod[i]=='0' && kod[i+1]=='1'){
cout<<"K"<<endl;
//if(imie[0]=='B')cerr<<"K"<<endl;
string b;
cin>>b;
if(b=="K"){
ans+="01";
}else{
ans+="10";
cout<<"P"<<endl;
//if(imie[0]=='B')cerr<<"P"<<endl;
cin>>b;
}
}
}
}
if(a=="P" && moje == "K"){
cout<<"P"<<endl;
//if(imie[0]=='B')cerr<<"P"<<endl;
cin>>a;
ans+="11";
}
if(a=="K" && moje == "P"){
cout<<"K"<<endl;
//if(imie[0]=='B')cerr<<"K"<<endl;
cin>>a;
ans+="00";
}
if(a=="N" && moje=="P"){
cout<<"P"<<endl;
//if(imie[0]=='B')cerr<<"P"<<endl;
string b;
cin>>b;
if(b=="P"){
ans+="10";
cout<<"P";
//if(imie[0]=='B')cerr<<"P";
cin>>b;
}else if(b=="K"){
ans+="01";
}
}
if(a=="P" && moje=="N"){
ans+="11";
string b;
if(kod[i]=='1'){
cout<<"P"<<endl;
//if(imie[0]=='B')cerr<<"P"<<endl;
cin>>b;
cout<<"K"<<endl;
//if(imie[0]=='B')cerr<<"K"<<endl;
cin>>b;
}else{
cout<<"K"<<endl;
cin>>b;
}
}
if(a=="N" && moje=="K"){
cout<<"P"<<endl;
//if(imie[0]=='B')cerr<<"P"<<endl;
string b;
cin>>b;
if(b=="P"){
ans+="10";
cout<<"P";
//if(imie[0]=='B')cerr<<"P";
cin>>b;
}else if(b=="N"){
ans+="01";
}
}
if(a=="K" && moje=="N"){
ans+="00";
string b;
if(kod[i]=='1'){
cout<<"P"<<endl;
cin>>b;
cout<<"N"<<endl;
cin>>b;
}else{
cout<<"N"<<endl;
cin>>b;
}
}
}
if(ans.size() > unsigned(n)){
ans.pop_back();
}
cout<<"! "<<ans<<endl;
//if(imie[0]=='B')cerr<<"! "<<ans<<endl;
}
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | #include <bits/stdc++.h> using namespace std; typedef long long LL; int main() { ios_base::sync_with_stdio(false); string imie; int n, t; cin>>imie>>n>>t; while(t--){ string kod; cin>>kod; string ans; if(kod.size()%2==1)kod+="0"; for(unsigned i=0; i<kod.size(); i+=2){ string moje; if(kod[i]==kod[i+1] && kod[i]=='1'){ cout<<"P"<<endl; //if(imie[0]=='B')cerr<<"P"<<endl; moje="P"; }else if(kod[i]==kod[i+1] && kod[i] =='0'){ cout<<"K"<<endl; //if(imie[0]=='B')cerr<<"K"<<endl; moje="K"; }else{ cout<<"N"<<endl; //if(imie[0]=='B')cerr<<"N"<<endl; moje="N"; } string a; cin>>a; if(a==moje){ if(a=="P"){ ans+="11"; }else if(a=="K"){ ans+="00"; }else{ if(kod[i]=='1' && kod[i+1]=='0'){ cout<<"P"<<endl; //if(imie[0]=='B')cerr<<"P"<<endl; string b; cin>>b; if(b=="P"){ ans+="10"; }else{ ans+="01"; cout<<"K"<<endl; //if(imie[0]=='B')cerr<<"K"<<endl; cin>>b; } } if(kod[i]=='0' && kod[i+1]=='1'){ cout<<"K"<<endl; //if(imie[0]=='B')cerr<<"K"<<endl; string b; cin>>b; if(b=="K"){ ans+="01"; }else{ ans+="10"; cout<<"P"<<endl; //if(imie[0]=='B')cerr<<"P"<<endl; cin>>b; } } } } if(a=="P" && moje == "K"){ cout<<"P"<<endl; //if(imie[0]=='B')cerr<<"P"<<endl; cin>>a; ans+="11"; } if(a=="K" && moje == "P"){ cout<<"K"<<endl; //if(imie[0]=='B')cerr<<"K"<<endl; cin>>a; ans+="00"; } if(a=="N" && moje=="P"){ cout<<"P"<<endl; //if(imie[0]=='B')cerr<<"P"<<endl; string b; cin>>b; if(b=="P"){ ans+="10"; cout<<"P"; //if(imie[0]=='B')cerr<<"P"; cin>>b; }else if(b=="K"){ ans+="01"; } } if(a=="P" && moje=="N"){ ans+="11"; string b; if(kod[i]=='1'){ cout<<"P"<<endl; //if(imie[0]=='B')cerr<<"P"<<endl; cin>>b; cout<<"K"<<endl; //if(imie[0]=='B')cerr<<"K"<<endl; cin>>b; }else{ cout<<"K"<<endl; cin>>b; } } if(a=="N" && moje=="K"){ cout<<"P"<<endl; //if(imie[0]=='B')cerr<<"P"<<endl; string b; cin>>b; if(b=="P"){ ans+="10"; cout<<"P"; //if(imie[0]=='B')cerr<<"P"; cin>>b; }else if(b=="N"){ ans+="01"; } } if(a=="K" && moje=="N"){ ans+="00"; string b; if(kod[i]=='1'){ cout<<"P"<<endl; cin>>b; cout<<"N"<<endl; cin>>b; }else{ cout<<"N"<<endl; cin>>b; } } } if(ans.size() > unsigned(n)){ ans.pop_back(); } cout<<"! "<<ans<<endl; //if(imie[0]=='B')cerr<<"! "<<ans<<endl; } return 0; } |
English