fork download
  1. /*
  2. * @Author: hungeazy
  3. * @Date: 2026-03-04 23:24:15
  4. * @Last Modified by: hungeazy
  5. * @Last Modified time: 2026-03-16 21:33:44
  6. */
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12. string s;
  13. getline(cin,s);
  14. while (s[0] == ' ') s.erase(0,1);
  15. while (s.back() == ' ') s.erase(s.size()-1,1);
  16. int i = 0;
  17. while (i < s.size())
  18. {
  19. while (s[i] == ' ' and s[i+1] == ' ') s.erase(i,1);
  20. i++;
  21. }
  22. s += ' ';
  23. int ans = 0;
  24. for (int i = 0; i < s.size(); i++)
  25. if (s[i] == ' ') ans++;
  26. cout << ans;
  27. return 0;
  28. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
1