Don't like ads? PRO users don't see any ads ;-)
Guest

Reverse Words

By: a guest on Aug 11th, 2012  |  syntax: C++  |  size: 0.51 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <iostream>
  2. # include <sstream>
  3. #include <string>
  4. # include <vector>
  5. using namespace std;
  6. int main ()
  7. {
  8.         string str,temp;
  9.         vector<string>v;
  10.         int t;
  11.         cin>>t;
  12.         cin.ignore();
  13.         for (int i=0; i<t; i++)
  14.         {
  15.                 getline(cin,str);
  16.                 stringstream ss (str);
  17.                 while (!ss.eof())
  18.                 {
  19.                         ss>>temp;
  20.                         v.push_back(temp);
  21.                         temp.clear();
  22.                 }
  23.                 reverse(v.begin(), v.end());
  24.                 cout<<"Case #"<<i+1<<": ";
  25.                 for (int j=0; j<v.size(); j++)
  26.                         cout<<v[j]<<' ';
  27.                 cout<<endl;
  28.                 v.clear();
  29.         }
  30.         return 0;
  31. }