https://www.acmicpc.net/problem/10820
문제는 간단하고 어렵지는 않지만 fgets()와 EOF에 대해 알 수 있는 문제이다.
배열의 크기를 101로 잡게 되면 틀린다!
getchar()를 이용해서 하나씩 받아와도 무관하다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <cstdio> using namespace std; char input[102]; int main() { while(fgets(input, 102, stdin)) { int small = 0, capital = 0, num = 0, space = 0; for (int i = 0; input[i]; i++) { if ('a' <= input[i] && input[i] <= 'z') //small letter small++; else if ('A' <= input[i] && input[i] <= 'Z') //capital letter capital++; else if ('0' <= input[i] && input[i] <= '9') //number num++; else if (input[i] == ' ') //space space++; } printf("%d %d %d %d\n", small, capital, num, space); } return 0; } | cs |
<Amazing Code From https://www.acmicpc.net/source/4430326>
1 2 3 4 5 6 7 8 9 10 11 12 13 | #include <cstdio> int a,A,n,s; char c; int main() { while(~(c=getchar())) { if(c>='a' && c<='z') a++; if(c>='A' && c<='Z') A++; if(c>='0' && c<='9') n++; if(c==' ') s++; if(c=='\n') printf("%d %d %d %d\n", a,A,n,s), a=A=n=s=0; } return 0; } | cs |
'Algorithm Problems > BOJ' 카테고리의 다른 글
[1065번] 한수 - Bruth force & Search[C++] (0) | 2017.03.27 |
---|---|
[1181번] 단어 정렬 - Sorting[C++] (0) | 2017.03.27 |
[10809번] 알파벳 찾기 - String[C++] (1) | 2017.03.15 |
[10808번] 알파벳 개수 - string[C++] (0) | 2017.03.13 |
[10828번] 스택 Stack - Stack[C++] (0) | 2017.03.13 |