fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. string s;
  5.  
  6. int main() {
  7. ios::sync_with_stdio(0); cin.tie(0);
  8. int num = 1;
  9. getline(cin, s); // 공백이 있는 문자열 입력 시 사용
  10.  
  11. if (s.empty())
  12. {
  13. cout << 0;
  14. return 0;
  15. }
  16.  
  17. for (int i = 1; i < s.length() - 1; i++)
  18. {
  19. if (s[i] == ' ') {
  20. num++;
  21. }
  22. }
  23.  
  24. cout << num;
  25. }
Success #stdin #stdout 0.01s 5440KB
stdin
 
stdout
1