Skip to content

Instantly share code, notes, and snippets.

@cengiz-io
Created December 14, 2014 23:08
Show Gist options
  • Save cengiz-io/5e08a2a81e7c2fdd0917 to your computer and use it in GitHub Desktop.
Save cengiz-io/5e08a2a81e7c2fdd0917 to your computer and use it in GitHub Desktop.
CodeEval Challange 8 - Reverse Words
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
using namespace std;
int main(int argc, const char * argv[]) {
string line;
while (getline(cin, line)) {
if (line.length() < 1) continue;
stringstream stream(line);
string buffer;
stack<string> words;
while (stream >> buffer) {
words.push(buffer);
}
while (! words.empty()) {
cout << words.top();
words.pop();
if (! words.empty()) {
cout << " ";
}
}
cout << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment