#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
cin.tie(0);
ios::sync_with_stdio(0);
//Algosia, Bajtek
string mode;
cin >> mode;
int n, t;
cin >> n >> t;
string info;
string opponentInfo;
int myWsk{};
int opponentWsk{};
int result{};// +1, -1
char send, receive;
for (int k = 0; k < t; ++k)
{
result = 0;
myWsk = 0;
opponentWsk = 0;
opponentInfo = "";
cin >> info;
while (1)
{
if (result == 0)
{
//00 P
//01 K
//1x N
if (myWsk < n - 1)
{
if (info[myWsk] == '0' && info[myWsk + 1] == '0')
{
send = 'P';
myWsk += 2;
}
else if (info[myWsk] == '0' && info[myWsk + 1] == '1')
{
send = 'K';
myWsk += 2;
}
else
{
send = 'N';
myWsk++;
}
}
else if (myWsk < n)
{
if (info[myWsk] == '0') send = 'P';
else send = 'N';
myWsk++;
}
else
{
//wszystko wyslane
send = 'N'; // najwieksza szansza na N
}
cout << send << endl;
cin >> receive;
if (opponentWsk < n - 1)
{
if (receive == 'P')
{
opponentInfo.push_back('0');
opponentInfo.push_back('0');
opponentWsk += 2;
}
else if (receive == 'K')
{
opponentInfo.push_back('0');
opponentInfo.push_back('1');
opponentWsk += 2;
}
else
{
opponentInfo.push_back('1');
opponentWsk += 1;
}
}
else if (opponentWsk < n)
{
if (receive == 'P') opponentInfo.push_back('0');
else opponentInfo.push_back('1');
opponentWsk++;
}
}
else if (result == 1)
{
//musze przegrac albo remis
//przeciwnik wszystko wyslal -> reset do remisu
send = 'P';
cout << send << endl;
cin >> receive;
if (opponentWsk < n)
{
if (receive == 'P')
{
opponentInfo.push_back('0');
}
else
{
opponentInfo.push_back('1');
}
opponentWsk++;
}
}
else if (result == -1)
{
//N, P
// musze wygrac, lub remis
if (myWsk == n)
{
//reset do remisu -> musze wygrac
send = 'N';
}
else if (info[myWsk] == '0')
{
send = 'P';
++myWsk;
}
else if (info[myWsk] == '1')
{
send = 'N';
myWsk++;
}
cout << send << endl;
cin >> receive;
}
//wynik
if (send != receive)
{
if (send == 'P' && receive == 'K' ||
send == 'K' && receive == 'N' ||
send == 'N' && receive == 'P')
{
result++;
}
else
{
result--;
}
}
if (myWsk == n && opponentWsk == n)
{
cout << "! " << opponentInfo << endl;
break;
}
}
}
}
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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | #include <iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(0); //Algosia, Bajtek string mode; cin >> mode; int n, t; cin >> n >> t; string info; string opponentInfo; int myWsk{}; int opponentWsk{}; int result{};// +1, -1 char send, receive; for (int k = 0; k < t; ++k) { result = 0; myWsk = 0; opponentWsk = 0; opponentInfo = ""; cin >> info; while (1) { if (result == 0) { //00 P //01 K //1x N if (myWsk < n - 1) { if (info[myWsk] == '0' && info[myWsk + 1] == '0') { send = 'P'; myWsk += 2; } else if (info[myWsk] == '0' && info[myWsk + 1] == '1') { send = 'K'; myWsk += 2; } else { send = 'N'; myWsk++; } } else if (myWsk < n) { if (info[myWsk] == '0') send = 'P'; else send = 'N'; myWsk++; } else { //wszystko wyslane send = 'N'; // najwieksza szansza na N } cout << send << endl; cin >> receive; if (opponentWsk < n - 1) { if (receive == 'P') { opponentInfo.push_back('0'); opponentInfo.push_back('0'); opponentWsk += 2; } else if (receive == 'K') { opponentInfo.push_back('0'); opponentInfo.push_back('1'); opponentWsk += 2; } else { opponentInfo.push_back('1'); opponentWsk += 1; } } else if (opponentWsk < n) { if (receive == 'P') opponentInfo.push_back('0'); else opponentInfo.push_back('1'); opponentWsk++; } } else if (result == 1) { //musze przegrac albo remis //przeciwnik wszystko wyslal -> reset do remisu send = 'P'; cout << send << endl; cin >> receive; if (opponentWsk < n) { if (receive == 'P') { opponentInfo.push_back('0'); } else { opponentInfo.push_back('1'); } opponentWsk++; } } else if (result == -1) { //N, P // musze wygrac, lub remis if (myWsk == n) { //reset do remisu -> musze wygrac send = 'N'; } else if (info[myWsk] == '0') { send = 'P'; ++myWsk; } else if (info[myWsk] == '1') { send = 'N'; myWsk++; } cout << send << endl; cin >> receive; } //wynik if (send != receive) { if (send == 'P' && receive == 'K' || send == 'K' && receive == 'N' || send == 'N' && receive == 'P') { result++; } else { result--; } } if (myWsk == n && opponentWsk == n) { cout << "! " << opponentInfo << endl; break; } } } } |
English