Advertisement
nGenchev

povtarqshti_se_v2.cpp

Mar 30th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <list>
  4. using namespace std;
  5.  
  6. void echo(list<int> L)
  7. {
  8.     list<int>::iterator it;
  9.     for(it=L.begin();it!=L.end();it++)
  10.         cout << *it << " ";
  11. }
  12.  
  13. int main()
  14. {
  15.     list<int>L, L2;
  16.     list<int>::iterator myIt_1, myIt_2, myIt_3;
  17.    
  18.     int n;
  19.     cin>>n;
  20.    
  21.     for(int i = 1; i <= n; i++)
  22.     {
  23.         int ch;
  24.         cin>>ch;
  25.         L.push_back(ch);
  26.     }
  27.     int size = L.size(), element = 1, br = 0;
  28.    
  29.     for(myIt_1=L.begin();myIt_1!=L.end();myIt_1++)
  30.     {
  31.         myIt_2 = myIt_1;
  32.         for(int i = element+1; i<=size; i++)
  33.             {
  34.                 myIt_2++;
  35.                 if(*myIt_1 == *myIt_2)
  36.                 {
  37.                     bool isThere = false;
  38.                     for(myIt_3=L2.begin();myIt_3!=L2.end();myIt_3++)
  39.                         if(*myIt_3 == *myIt_2) isThere = true;
  40.                     if(!isThere)
  41.                         L2.push_back(*myIt_2);
  42.                     br++;
  43.                 }
  44.                 //cout << *myIt_1 << " <> " << *myIt_2 << " \n\r";
  45.             }
  46.         //cout << "\n";
  47.         element++;
  48.     }
  49.    
  50.     if(br > 0 && !L2.empty())
  51.     {
  52.         cout << "Povtarqshti se chisla: " << endl;;
  53.         L2.sort();
  54.         echo(L2);
  55.     } else cout << "Nqma povtarqshti se chisla.." << endl;;
  56.        
  57.     system("pause");       
  58.            
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement