fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <string>
  6. #include <cmath>
  7. #include <cstdlib>
  8. #include <cstring>
  9. #include <map>
  10. #include <iterator>
  11. #include <cctype>
  12. using namespace std;
  13.  
  14. int main()
  15. {
  16. //freopen("B-large-practice.in","r",stdin);
  17. //freopen("output.txt","w",stdout);
  18. int n;
  19. scanf("%d",&n);
  20.  
  21. getchar();
  22. for (int t = 1; t <= n; t++) {
  23. string str;
  24. getline(cin,str);
  25.  
  26. string word;
  27. vector<string> tokens;
  28. tokens.clear();
  29. for (int i=0; i<str.size(); i++) {
  30. if (str[i]==' ' || i == str.size()-1) {
  31. if (i == str.size()-1)
  32. word+=str[i];
  33. tokens.push_back(word);
  34. word.clear();
  35. } else {
  36. word += str[i];
  37. }
  38. }
  39.  
  40. vector<string>::iterator j;
  41. cout << "Case #" << t << ": ";
  42. for (j=tokens.end()-1;j>=tokens.begin();j--)
  43. cout << *j << " ";
  44. cout << endl;
  45. }
  46. }
  47.  
Success #stdin #stdout 0s 3464KB
stdin
3
this is a test
foobar
all your base
stdout
Case #1: test a is this 
Case #2: foobar 
Case #3: base your all