aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-03-08 13:21:10 +0900
committernsfisis <nsfisis@gmail.com>2025-03-08 13:21:10 +0900
commit43cc82f561ac3fa879d59cb31e09591d204e8339 (patch)
treef9d5c0900af785769477be4b4981cd3275e3d4f3
parent36443a0f1967cae60d772f70cf5d0c00f2e290ed (diff)
downloadiosdc-japan-2025-albatross-43cc82f561ac3fa879d59cb31e09591d204e8339.tar.gz
iosdc-japan-2025-albatross-43cc82f561ac3fa879d59cb31e09591d204e8339.tar.zst
iosdc-japan-2025-albatross-43cc82f561ac3fa879d59cb31e09591d204e8339.zip
wip
-rw-r--r--q1.sql17
-rw-r--r--q2.sql112
2 files changed, 129 insertions, 0 deletions
diff --git a/q1.sql b/q1.sql
new file mode 100644
index 0000000..ca9ee15
--- /dev/null
+++ b/q1.sql
@@ -0,0 +1,17 @@
+INSERT INTO problems (title, description, sample_code)
+VALUES
+ ('練習問題', '', ''),
+ ('九九', '', ''),
+ ('いろは', '', ''),
+ ('グルーピング', '', ''),
+ ('しりとり', '', ''),
+ ('ポップカウント', '', '');
+
+INSERT INTO games (game_type, is_public, display_name, duration_seconds, problem_id)
+VALUES
+ ('multiplayer', true, '練習問題', 900, 21),
+ ('multiplayer', true, '予選ラウンド1', 900, 22),
+ ('multiplayer', true, '予選ラウンド2', 900, 23),
+ ('multiplayer', true, '予選ラウンド3', 900, 24),
+ ('1v1', true, 'エキシビション1', 900, 25),
+ ('1v1', true, 'エキシビション2', 900, 26);
diff --git a/q2.sql b/q2.sql
new file mode 100644
index 0000000..21067a6
--- /dev/null
+++ b/q2.sql
@@ -0,0 +1,112 @@
+UPDATE problems
+SET
+sample_code = $EOF$$line = fgets(STDIN);
+$number = intval($line);
+echo $number * $number, PHP_EOL;
+$EOF$
+WHERE title = '練習問題';
+
+UPDATE problems
+SET
+sample_code = $EOF$fscanf(STDIN, "%d %d", $col, $row);
+
+for ($i = 1; $i <= $row; $i++) {
+ for ($j = 1; $j <= $col; $j++) {
+ printf(str_repeat(" ", strlen($col * $row) - strlen($j * $i) + 1));
+ printf("%d", $i * $j);
+ }
+ printf("\n");
+}
+$EOF$
+WHERE title = '九九';
+
+UPDATE problems
+SET
+sample_code = $EOF$$lines = [];
+while ($line = fgets(STDIN)) {
+ $lines[] = rtrim($line);
+}
+
+function to_iroha($chars) {
+ return implode(',',array_map(fn ($c) => match($c) {
+ 'い' => 0, 'ろ' => 1, 'は' => 2, 'に' => 3, 'ほ' => 4, 'へ' => 5, 'と' => 6,
+ 'ち' => 7, 'り' => 8, 'ぬ' => 9, 'る' => 10, 'を' => 11,
+ }, mb_str_split($chars)));
+}
+
+usort($lines, function (string $a, string $b): int {
+ $as = to_iroha($a);
+ $bs = to_iroha($b);
+
+ if ($as === $bs) {
+ return 0;
+ } else {
+ return ($as > $bs) ? 1 : -1;
+ }
+});
+
+foreach ($lines as $line) echo $line, PHP_EOL;
+$EOF$
+WHERE title = 'いろは';
+
+UPDATE problems
+SET
+sample_code = $EOF$$result = [];
+while ([$a, $b] = fgetcsv(STDIN, 1024, ',', '"', '')) {
+ if (!isset($result[$a])) {
+ $result[$a] = [$b];
+ } else {
+ $result[$a][] = $b;
+ }
+}
+ksort($result);
+foreach ($result as $i => $v) {
+ sort($v);
+ fputcsv(STDOUT, array_merge([$i], $v), ',', '"', '');
+}
+$EOF$
+WHERE title = 'グルーピング';
+
+UPDATE problems
+SET
+sample_code = $EOF$$lines = [];
+while ($line = fgets(STDIN)) {
+ $lines[] = rtrim($line);
+}
+
+$current = array_shift($lines);
+$words = $lines;
+$lines = [];
+echo $current, "\n";
+do {
+ $last = mb_str_split($current)[mb_strlen($current)-1];
+ if ($last === 'ン') {
+ echo "負けました\n";
+ break;
+ }
+ foreach ($words as $i => $word) {
+ if (str_starts_with($word, $last)) {
+ echo $word, "\n";
+ unset($words[$i]);
+ $current = $word;
+ continue 2;
+ }
+ }
+ exit("おかしいな\n");
+} while(true);
+$EOF$
+WHERE title = 'しりとり';
+
+UPDATE problems
+SET
+sample_code = $EOF$while($line = fgets(STDIN)) {
+ $line = rtrim($line, "\n");
+ $count = 0;
+ foreach (str_split($line) as $char) {
+ $bits = str_split(decbin(ord($char)));
+ $count = $count + count(array_filter($bits, fn($c)=> $c == 1));
+ }
+ echo $count, PHP_EOL;
+}
+$EOF$
+WHERE title = 'ポップカウント';