[SWEA] 6959 이상한 나라의 덧셈게임

Time Lapse :5min 2sec

6959.c

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
#include <stdio.h>
#define gc() getchar_unlocked()
#define pc(x) putchar_unlocked(x)
#define reg register
int fRI() {
reg int N = gc(), r = 0;
for (;48 > N || N > 57; N = gc());
do {
r = (r << 3) + (r << 1) + (N & 0b1111); N = gc();
} while (48 <= N);
return r;
}
void fWI(int tc) {
reg int r = 0, c = 0;
pc(0x23);
while (!(tc % 10)) { c++; tc /= 10; }
while (tc) { r = (r << 3) + (r << 1) + (tc % 10); tc /= 10; }
while (r) { pc(r % 10 | 0b110000); r /= 10; }
while (c--) pc(0x30); pc(32);
}
int main(void) {
reg int tc = 1, T = fRI(), c, s, input;
while (T--) {
c = s = 0;
while (input = gc(), 48 <= input) {
s = (s << 3) + (s << 1) + (input & 0b1111);
while (s >= 10) {
s = s % 10 + s / 10;
c ^= 1;
}
}
fWI(tc++);
c & 1 ? pc(0x41) : pc(0x42);
pc(0x0A);
}
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/08/04/PS/SWEA/6959/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.