Public paste
asdf
By: asdf | Date: Nov 29 2007 22:27 | Format: C++ | Expires: never | Size: 3.82 KB | Hits: 1140

  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.     queue<char> q2;
  14.     stack<char> s;
  15.     stack<char> s2;
  16.     stack<char> s3;
  17.     stack<char> s4;
  18.     ifstream infile;
  19.     ofstream outfile;
  20.     char ch;
  21.     char j;
  22.     char r;
  23.     string str;
  24.     string sent;
  25.    // int y; debugging purposes
  26.     string k;
  27.      
  28.     infile.open("input5.txt");
  29.     outfile.open("output5.txt");
  30.      
  31.     if(!infile)
  32.     {
  33.       cerr<< "NO FILE!!!!!!n";
  34.       system("PAUSE");
  35.       return 1;  
  36.       }
  37.        
  38.  
  39.      
  40.     while(getline(infile,str))
  41.      {
  42.                                
  43.         q.push(str);  // queue of sentence
  44.           }
  45.          
  46.         while(!q.empty())
  47.         {
  48.         sent = q.front();   // sets sent to first sentence
  49.        
  50.          
  51.        //   y = sent.size();  // checks size of first sentence
  52.          // cout << y << endl;
  53.           for (int m=0;m<sent.length();m++)  
  54.            {
  55.             s.push(sent[m]);  // puts first sentence into stack
  56.             }
  57.              
  58.              
  59.               while(!s.empty())  
  60.               {
  61.              
  62.              if(ispunct(s.top()))  //finds punctuations and adds them to k
  63.    
  64.                   {
  65.                   j = s.top();       //if punct, set j to punct
  66.                   k = (k +=j);
  67.                   s2.push(' ');
  68.              
  69.                    
  70.                   }
  71.                 else
  72.                  
  73.                     s2.push(s.top());  
  74.                      s.pop();
  75.  
  76.                      }
  77.                      
  78.                      j = k[0];
  79.                      
  80.            
  81.    while(!s2.empty())
  82.                   {  
  83.                      
  84.                      if(isspace(s2.top()))
  85.                       {
  86.                      s3.push(j);
  87.                  
  88.                      }
  89.                      else
  90.                      s3.push(s2.top());
  91.                      s2.pop();
  92.                      }                       //?lleh?eht??woh
  93.              
  94.              while(!s3.empty())
  95.              {
  96.               s.push(s3.top());
  97.               s3.pop();
  98.               }                               //how??the?hell?
  99.  
  100.  
  101. cout << q.size();                     // this still says i have the last
  102.                                          // sentence in but will not output
  103.           while(!s.empty())
  104.              {
  105.                   s4.push(s.top());
  106.                   s.pop();
  107.  
  108.                 if(ispunct(s4.top()))
  109.                 {
  110.                           r = s4.top();        
  111.                           s4.pop();
  112.                              
  113.                          while(!s4.empty())
  114.                          
  115.                         {
  116.                             q2.push(s4.top());
  117.                             s4.pop();
  118.                             }  
  119.                            q2.push(r);
  120.                              
  121.                  
  122.            
  123.             }
  124.               else  if(isspace(s4.top()))
  125.               {
  126.                    
  127.                     s4.pop();
  128.                    
  129.                        while(!s4.empty())
  130.                          
  131.                         {
  132.                             q2.push(s4.top());
  133.                             s4.pop();
  134.                             }  
  135.                            q2.push(' ');
  136. }
  137.             }
  138.             while(!q2.empty())
  139.             {
  140.             cout << q2.front();
  141.             q2.pop();
  142.             }
  143.            
  144.             cout << endl << endl;
  145.             k.clear();
  146.             q.pop();
  147.             }
  148.      
  149.                          
  150.     system("PAUSE");
  151.  
  152.     return EXIT_SUCCESS;
  153. }