fork download
  1. #include<iostream>
  2. #include <cctype>
  3. using namespace std;
  4. int main() {
  5. string st;
  6. int count_alpha = 0;
  7. int count_word = 0;
  8. getline(cin, st);
  9. for (int i = 0; i < st.size(); i++) {
  10. while ((st[i] >= 'A' && st[i] <= 'Z') || (st[i] >= 'a' && st[i] <= 'z')) {
  11. count_alpha++;
  12. i++;
  13. }
  14. if (st[i] == ' ' && count_alpha != 0) {
  15. count_word++;
  16. count_alpha = 0;
  17. }
  18. }
  19. if (count_alpha != 0)
  20. count_word++;
  21. cout << count_word;
  22. return 0;
  23. }
  24. //65 90 97 122
  25. //A Z a z
  26. //32 33 46 44 63
  27. //sp ! . , ?
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
Standard output is empty