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.  
  10. int k ;
  11. cin >> k;
  12. while (k--) {
  13. string space="";
  14. cin.ignore();
  15. getline(cin, space);
  16. int z = space.length();
  17. int n = 0;
  18. for (int i = 0; i <z-1; i++)
  19. {
  20. if (space[i] == ' ' && space[i + 1] != ' ')
  21. n++;
  22. }
  23. cout << n <<"\n";
  24. }
  25. }
  26.  
Success #stdin #stdout 0s 5696KB
stdin
2
abc   xyz ab
 abc def ghi
stdout
2
2