Public paste
n00b
By: jazy84 | Date: Nov 9 2007 22:23 | Format: C++ | Expires: never | Size: 1.09 KB | Hits: 803

  1. #include <iostream>
  2. #include <stack>
  3. #include <fstream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9. stack<char> myStack,tmpStack;
  10. ifstream inFile;
  11. inFile.open("input5.txt");
  12.  
  13. if (!inFile)
  14. cerr<<"Unable to open file input5.txt";
  15. string tmp;
  16. int n = 0;
  17. char x;
  18.  
  19. // Mystack will hold the orginal untouched word //
  20. while (getline(inFile,tmp)) {
  21. n = tmp.length();
  22.  
  23. for (int i=0;i<n;++i) {
  24. myStack.push(tmp[i]);
  25. }
  26.  
  27. }
  28. inFile.close();
  29.  
  30. inFile.open("input5.txt");
  31. cout<<"Our Orginal Wordn"<<tmp<<endl;
  32. cout<<"Ever word reveresed. last punctuation in whitespacen";
  33. while (!inFile.eof()) {
  34.  
  35. x = inFile.get();
  36. tmpStack.push(x);
  37.  
  38. if (x == ' ') {
  39. tmpStack.pop();
  40. tmpStack.push(myStack.top());
  41. n = tmpStack.size();
  42. for (int i=0;!tmpStack.empty();i++) {
  43. cout<<tmpStack.top();
  44. tmpStack.pop();
  45. }
  46. }
  47.  
  48. }
  49. // Now to print out the last one //
  50. n = tmpStack.size();
  51. //Pop of the garbage we are getting as the last char //
  52. tmpStack.pop();
  53.  
  54. for (int i=0;!tmpStack.empty();++i, tmpStack.pop())
  55. cout<<tmpStack.top();
  56. cout<<myStack.top()<<"n";
  57.  
  58. inFile.close();
  59.  
  60.  
  61.  
  62. return 0;
  63. }