BOJ : https://www.acmicpc.net/problem/10820
10820번: 문자열 분석
문자열 N개가 주어진다. 이때, 문자열에 포함되어 있는 소문자, 대문자, 숫자, 공백의 개수를 구하는 프로그램을 작성하시오. 각 문자열은 알파벳 소문자, 대문자, 숫자, 공백으로만 이루어져 있다.
www.acmicpc.net
scanf("....") != EOF 가 핵심이다.
EOF 를 처리하는 방법을 안다면 쉽게 해결할 수 있는 문제이다.
더보기
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
|
#include <cstdio>
#include <string.h>
#pragma warning(disable:4996)
char arr[100];
int main() {
int s, b, num, nul;
int len = 0;
while (scanf("%c",&arr[len]) != EOF) {
if (arr[len] != '\n') {
len++;
continue;
}
s = b = num = nul = 0;
for (int i = 0; i < len; i++) {
if (arr[i] >= 'a' && arr[i] <= 'z') s++;
if (arr[i] >= 'A' && arr[i] <= 'Z') b++;
if (arr[i] >= '0' && arr[i] <= '9') num++;
if (arr[i] == ' ') nul++;
}
printf("%d %d %d %d\n", s, b, num, nul);
len = 0;
}
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
'algorithm > BOJ' 카테고리의 다른 글
BOJ 11656번 접미사 배열 (0) | 2020.01.12 |
---|---|
BOJ 11655번 ROT13 (0) | 2020.01.12 |
BOJ 10809번 알파벳 찾기 (0) | 2020.01.12 |
BOJ 10845 큐 (0) | 2020.01.11 |
BOJ 10799번 쇠막대기 (0) | 2020.01.11 |