[SWEA] 3750 Digit sum

Time Lapse :11min 14sec

3750.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>

int main(int argc, char** argv)
{
register int test_case, answer;
int T;
char c;
scanf("%d",&T);
getchar();
for (test_case = 1; test_case <= T; ++test_case){
c = '0';
answer = 0;
while('0'<=c&&c<='9') {
answer += c - 48;
answer = answer >= 10 ? answer / 10 + answer % 10 : answer;
c = getchar();
}
printf("#%d %d\n",test_case,answer);
}
return 0; //정상종료시 반드시 0을 리턴해야 합니다.
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/08/04/PS/SWEA/3750/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.