fork download
  1. #include <cstdlib>
  2. #include <cstdio>
  3. #include <iostream>
  4.  
  5. #include <string>
  6.  
  7. #include <set>
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12.  
  13. {
  14.  
  15. int t;
  16. scanf("%d",&t);
  17. // see that the input is skipped by one line, un-comment it to make it work correctly
  18. //getchar();
  19. while(t>0)
  20. {
  21. t--;
  22. string line;
  23. getline(cin,line);
  24. line = line + " ";
  25. int prev = 0;
  26. set<string> myset;
  27. int i = 0;
  28. while(line[i]==' ')
  29. i++;
  30. prev = i;
  31. for(;i<(int)line.length();)
  32. {
  33. while(line[i]!=' ')
  34. i++;
  35. myset.insert(line.substr(prev,i-prev));
  36. while(line[i]==' ')
  37. i++;
  38. prev = i;
  39. }
  40. printf("%d\n",(int)myset.size());
  41. }
  42. }
Success #stdin #stdout 0s 3436KB
stdin
4
now do it now
now      do it now
I am  good boy
am am
stdout
0
3
3
4