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
#include <iostream>
#include <string>

int main()
{
    std::string name;
    std::cin >> name;
    const bool is_algosia = name == "Algosia";
    int n, t;
    std::cin >> n >> t;
    for (int i = 0; i < t; ++i)
    {
		std::string a, b;
		std::cin >> a;
        int al = 0;
        while (al < n && b.length() < n)
        {
            char sent;
            if (al < n)
            {
                sent = (a[al] == '0' ? 'P' : 'K');
                std::cout << sent << std::endl;
                ++al;
            }
			else
            {
                sent = 'P';
				std::cout << sent << std::endl;
            }
            char received;
            std::cin >> received;
            if (b.length() < n)
                b += received == 'P' ? '0' : '1';

            int result = 0;
            if ((sent == 'P' && received == 'K') ||
                (sent == 'K' && received == 'N') ||
                (sent == 'N' && received == 'P'))
                result = 1;
			else if ((sent == 'P' && received == 'N') ||
				(sent == 'K' && received == 'P') ||
				(sent == 'N' && received == 'K'))
				result = -1;
			if (result)
			{
				std::cout << (result < 0 ? 'P' : 'K') << std::endl;
				char dummy;
				std::cin >> dummy;
			}
        }
        std::cout << "! " << b << std::endl;
	}
    return 0;
}