[SWEA] 5672 올해의 조련사

Time Lapse :24min 45sec

5672.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
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
#include <stdio.h>
#define gc() getchar_unlocked()
#define pc(x) putchar_unlocked(x)
char birds[2000];
int ret , flag, n;
int fastReadINT(){
ret = 0, flag = 1, n = gc();
for(;'0'>n||n>'9';n=gc()){
if(n=='-'){
flag = -1; n=gc(); break;
}
}
do{
ret = (ret<<3) + (ret<<1) + (n & 0b1111); n = gc();
}while('0'<=n&&n<='9');
return ret*flag;
}
void fastWriteANSWER(int N){
pc('#');
if (n == 0) { pc('0'); pc('\n'); return ;}
if (n<0) { n = -n; pc('-');}
flag = 0, ret = n = N;
while ((ret % 10) == 0) { flag++; ret /= 10;}
ret = 0;
while (N != 0) { ret = (ret<<3) + (ret<<1) + N % 10; N /= 10;}
while (ret != 0) { pc(ret % 10 + '0'); ret /= 10;}
while (flag--) pc('0');
pc(' ');
}
int main(int argc, char** argv){
register int tc, T, N, front, back, cmp_front, cmp_back;
T = fastReadINT();
for(tc = 1; tc <= T; tc++){
N = fastReadINT();
back = front = 0;
while(back<N){
birds[back] = gc();
if('A'<=birds[back] && birds[back]<='Z')
back++;
}
back -= 1;
fastWriteANSWER(tc);
while(front!=back){
if(birds[front]==birds[back]){
cmp_front = front + 1;
cmp_back = back - 1;
while(birds[cmp_front]==birds[cmp_back]&&cmp_front<=cmp_back) {
cmp_front++;
cmp_back--;
}
if(birds[cmp_front]>birds[cmp_back]){
pc(birds[back--]);
}
else
pc(birds[front++]);
}
else if(birds[front]>birds[back])
pc(birds[back--]);
else
pc(birds[front++]);
}
pc(birds[front]);
pc('\n');

}
return 0;//정상종료시 반드시 0을 리턴해야합니다.
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/08/04/PS/SWEA/5672/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.