-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0049.php
More file actions
57 lines (41 loc) · 896 Bytes
/
0049.php
File metadata and controls
57 lines (41 loc) · 896 Bytes
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
<?php
// https://coderun.yandex.ru/problem/hack-pentagon
// constructive algorithm
$line = fgets(STDIN);
if ($line === false) {
exit();
}
$n = (int) trim($line);
$baseString = str_repeat("a", $n);
echo $baseString . "\n";
flush();
$response = fgets(STDIN);
if ($response === false) {
exit();
}
$baseDist = (int) trim($response);
if ($baseDist === 0) {
exit();
}
$password = "";
for ($i = 0; $i < $n; $i++) {
$baseString[$i] = "z";
echo $baseString . "\n";
flush();
$response = fgets(STDIN);
if ($response === false) {
exit();
}
$currentDist = (int) trim($response);
if ($currentDist === 0) {
exit();
}
$baseString[$i] = "a";
$delta = $currentDist - $baseDist;
$offset = (25 - $delta) / 2;
$char = chr(ord("a") + (int) $offset);
$password .= $char;
}
echo $password . "\n";
flush();
fgets(STDIN);