백준(C++)/자료구조1
[BOJ/C++]10820번_문자열 분석
코잼민
2024. 7. 19. 20:58
https://www.acmicpc.net/problem/10820
##문제 풀기 전 알아야 할 개념 :
※★while(getline(cin,string 객체text)){..} :
- 기능 1 : 한 줄 씩 입력받아 그 text 단위로 측정하는 기능 (엔터 단위로)
- 기능 2 : getline(cin,string 객체text)) 메소드 내에 제한조건인, 문자열 크기 100이 넘지 않는다는것이 내포되어있다.
#코드
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
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string total="";
int len = 0;
int a = 0, A = 0, n = 0, b = 0;
while (len<=100) {
string text;
getline(cin, text, '\n');
for (int i = 0; i < text.length(); i++) {
char c = text[i];
if (c == ' ') {
b++;
}
else if (c >= '0' && c <= '9') {
n++;
}
else if (c >= 'A' && c <= 'Z') {
A++;
}
else if (c >= 'a' && c <= 'z') {
a++;
}
}
cout << a << ' ' << A << ' ' << n << ' ' << b << '\n';
A = a = b = n = 0;
}
return 0;
}
|
cs |