알고리즘 문제/BOJ
1152번 단어의 개수
parkit
2019. 9. 15. 00:24
728x90
반응형
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 | #include <bits/stdc++.h> using namespace std; int main(void) { int ans = 0; string s, word = ""; getline(cin, s); for (auto i : s) if (i == ' ') { if (word.length() >= 1) { word = ""; ++ans; } } else word += i; printf("%d\n", word.length() >= 1 ? ans + 1 : ans); return 0; } | cs |
728x90
반응형