Public paste
asdf
By: asdf | Date: Nov 29 2007 07:52 | Format: C++ | Expires: never | Size: 2.47 KB | Hits: 1226

  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <stack>
  4. #include <fstream>
  5. #include <queue>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main()
  11. {  
  12.     queue<string> q;
  13.     stack<char> s;
  14.     stack<char> s2;
  15.     stack<char> s3;
  16.     ifstream infile;
  17.     ofstream outfile;
  18.     char ch;
  19.     char j;
  20.     string str;
  21.     string sent;
  22.    // int y; debugging purposes
  23.     string k;
  24.    
  25.     infile.open("input5.txt");
  26.     outfile.open("output5.txt");
  27.    
  28.     if(!infile)
  29.     {
  30.       cerr<< "NO FILE!!!!!!n";
  31.       system("PAUSE");
  32.       return 1;  
  33.       }
  34.      
  35.  
  36.    
  37.     while(getline(infile,str))
  38.      {
  39.         q.push(str);  // queue of sentence
  40.           }
  41.         while(!q.empty())
  42.         {
  43.         sent = q.front();   // sets sent to first sentence
  44.  
  45.        
  46.        //   y = sent.size();  // checks size of first sentence
  47.          // cout << y << endl;
  48.           for (int m=0;m<sent.length();m++)
  49.            {
  50.             s.push(sent[m]);  // puts first sentence into stack
  51.             }
  52.              
  53.            
  54.               while(!s.empty())  
  55.               {
  56.              
  57.              if(ispunct(s.top()))  //finds punctuations and adds them to k
  58.    
  59.                   {
  60.                   j = s.top();       //if punct, set j to punct
  61.                   k = (k +=j);
  62.                   s2.push(' ');
  63.            
  64.                  
  65.                   }
  66.                 else
  67.                
  68.                     s2.push(s.top());
  69.                      s.pop();
  70.  
  71.                      }
  72.                      
  73.                      j = k[0];
  74.                      
  75.          
  76.    while(!s2.empty())
  77.                   {  
  78.                      
  79.                      if(isspace(s2.top()))
  80.                       {
  81.                      s3.push(j);
  82.                  
  83.                      }
  84.                      else
  85.                      s3.push(s2.top());
  86.                      s2.pop();
  87.                      }                       //?lleh?eht??woh
  88.              
  89.              while(!s3.empty())
  90.              {
  91.               s.push(s3.top());
  92.               s3.pop();
  93.               }                               //how??the?hell?
  94.  
  95.            
  96.            
  97.           while(!s.empty())
  98.              {
  99.              cout << s.top();
  100.              s.pop();
  101.              }
  102.             cout << endl << endl;
  103.             k.clear();
  104.             q.pop();
  105.             }
  106.    
  107.                        
  108.     system("PAUSE");
  109.  
  110.     return EXIT_SUCCESS;
  111. }