fork download
  1. #include<iostream>
  2. #include <iomanip>
  3. using namespace std;
  4. #include<fstream>
  5. #include<cmath>
  6. #include<string>
  7. int main()
  8. {
  9. string space="";
  10. int k ;
  11. cin >> k;
  12. while (k--) {
  13. cin.ignore();
  14. getline(cin, space);
  15. int k = space.length();
  16. int n = 0;
  17. for (int i = 0; i <k ; i++)
  18. {
  19. if (space[i] == ' ' && space[i + 1] != ' ')
  20. n++;
  21. }
  22. cout << n <<"\n";
  23. }
  24. }
Success #stdin #stdout 0.01s 5392KB
stdin
2
abc   xyz ab
 abc def ghi
stdout
2
2