포스트

백준 1152 - 단어의 개수 (Silver V)

출처: https://www.acmicpc.net/problem/1152

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
// 백준 1152 - 단어의 개수 (Silver V)
// https://www.acmicpc.net/problem/1152

// 문제 설명
// 영어 대소문자와 공백으로 이루어진 문자열에서 단어의 개수를 구한다.
// 단어는 공백 한 개로 구분되며, 문자열은 공백으로 시작하거나 끝날 수 있다.

// 입력
// 첫 줄: 영어 대소문자와 공백으로 이루어진 문자열 (길이 ≤ 1,000,000)

// 출력
// 첫째 줄에 단어의 개수 출력

// 입출력 예
// 입력:                              출력:
// The Curious Case of Benjamin Button    6
//  The first character is a blank        6
// The last character is a blank          6

#include <iostream>
#include <string>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int answer = 0;
    string word;
    while (cin >> word)
        answer++;
    cout << answer << "\n";
    return 0;
}
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.