
Reverse Words
By: a guest on
Aug 11th, 2012 | syntax:
C++ | size: 0.51 KB | hits: 22 | expires: Never
#include <iostream>
# include <sstream>
#include <string>
# include <vector>
using namespace std;
int main ()
{
string str,temp;
vector<string>v;
int t;
cin>>t;
cin.ignore();
for (int i=0; i<t; i++)
{
getline(cin,str);
stringstream ss (str);
while (!ss.eof())
{
ss>>temp;
v.push_back(temp);
temp.clear();
}
reverse(v.begin(), v.end());
cout<<"Case #"<<i+1<<": ";
for (int j=0; j<v.size(); j++)
cout<<v[j]<<' ';
cout<<endl;
v.clear();
}
return 0;
}