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(int argc, char *argv[]) { string input; int cnt, i; getline(cin, input, '\n'); if(input.length() == 0) { cnt = 0; } else { bool isAllSpace = true; for(i=0; i<input.length(); i++) { if(input.at(i) != ' ') { isAllSpace = false; break; } } if(isAllSpace) { cnt = 0; } else { cnt = 1; for(; i<input.length(); i++) { if(input.at(i) == ' ') { if((i>0) & (input.at(i-1) == ' ')) { cnt--; break; } else cnt++; } } if((input.at(input.length()-1) == ' ') & (input.at(input.length()-2) != ' ')) cnt--; } } cout << cnt << endl; return 0; } | cs |
'C & C++ > Baekjoon' 카테고리의 다른 글
백준 1316 - 그룹 단어 체커 (0) | 2017.12.27 |
---|---|
백준 1157 - 단어 공부 (0) | 2017.12.27 |
백준 1110 - 더하기 사이클 (0) | 2017.12.27 |
백준 1065 - 한수 (0) | 2017.12.27 |
백준 1008 - A/B (0) | 2017.12.27 |