-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprob_4.php
67 lines (50 loc) · 905 Bytes
/
prob_4.php
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
<?php
// $in = fopen("prob_4.txt", "r");
// $out = fopen("prob_4.out", "w");
$in = STDIN;
$out = STDOUT;
list($T, $B) = explode(' ', trim(fgets($in)));
for ($x = 1; $x <= $T; $x++) {
$bits = '';
for ($y = 0; $y < $B; $y++) {
$guess = $y + 1;
fputs($out, "$guess" . PHP_EOL);
flush();
$reply = trim(fgets($in));
switch ($reply) {
case 'N':
goto end3;
break;
case '1':
$bits .= '1';
break;
case '0':
$bits .= '0';
break;
case 'CORRECT':
goto end2;
break;
default:
break;
}
end:
}
fputs($out, "$bits" . PHP_EOL);
flush();
$reply2 = trim(fgets($in));
switch ($reply2) {
case 'N':
goto end3;
break;
case 'Y':
goto end2;
break;
default:
goto end2;
break;
}
end2:
}
end3:
fclose($in);
fclose($out);