Seal_of_approval

PrVecList5

Jul 3rd, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <list>
  4.  
  5. using namespace std;
  6.  
  7. int main (void)
  8. {
  9.     ifstream in("input.txt");
  10.     ofstream out("output.txt");
  11.  
  12.     int x, y;
  13.     int a;
  14.     list <int> ls;
  15.     list <int>::iterator i;
  16.    
  17.     while (in >> a)
  18.         ls.push_back(a);
  19.    
  20.     y = ls.back();
  21.     ls.pop_back();
  22.     x = ls.back();
  23.     ls.pop_back();
  24.    
  25.     for (i = ls.begin(); i != ls.end();)
  26.     {
  27.         a = *i;
  28.         if (a == x)
  29.         {
  30.             i++;
  31.             ls.insert(i, y);
  32.         }
  33.         else
  34.             i++;
  35.     }
  36.    
  37.     for (i = ls.begin(); i != ls.end(); i++)
  38.         out << *i << " ";
  39.    
  40. }
Advertisement
Add Comment
Please, Sign In to add comment