n00b
By: jazy84 | Date: Nov 9 2007 22:23 | Format: C++ | Expires: never | Size: 1.09 KB | Hits: 1272
- #include <iostream>
- #include <stack>
- #include <fstream>
- #include <string>
- using namespace std;
- int main() {
- stack<char> myStack,tmpStack;
- ifstream inFile;
- inFile.open("input5.txt");
- if (!inFile)
- cerr<<"Unable to open file input5.txt";
- string tmp;
- int n = 0;
- char x;
- // Mystack will hold the orginal untouched word //
- while (getline(inFile,tmp)) {
- n = tmp.length();
- for (int i=0;i<n;++i) {
- myStack.push(tmp[i]);
- }
- }
- inFile.close();
- inFile.open("input5.txt");
- cout<<"Our Orginal Wordn"<<tmp<<endl;
- cout<<"Ever word reveresed. last punctuation in whitespacen";
- while (!inFile.eof()) {
- x = inFile.get();
- tmpStack.push(x);
- if (x == ' ') {
- tmpStack.pop();
- tmpStack.push(myStack.top());
- n = tmpStack.size();
- for (int i=0;!tmpStack.empty();i++) {
- cout<<tmpStack.top();
- tmpStack.pop();
- }
- }
- }
- // Now to print out the last one //
- n = tmpStack.size();
- //Pop of the garbage we are getting as the last char //
- tmpStack.pop();
- for (int i=0;!tmpStack.empty();++i, tmpStack.pop())
- cout<<tmpStack.top();
- cout<<myStack.top()<<"n";
- inFile.close();
- return 0;
- }
Latest pastes
59 minutes ago
11 hours ago
1 days ago
2 days ago
2 days ago