daily pastebin goal
31%
SHARE
TWEET

Untitled

a guest Mar 26th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <list>
  3. #include<iterator>
  4. #include<string>
  5. using namespace std;
  6. list<string> list1;
  7. //list<string> list2;
  8.  
  9.  
  10.  
  11. int main()
  12. {
  13.     int n,i,nr;
  14.     string x;
  15.     cin>>n;
  16.     for (i=1; i<=n; i++)
  17.     {
  18.         cin>>x;
  19.         list1.push_back(x);
  20.     }
  21.     list<string> list2;
  22.     //list2.clear();
  23.  
  24.     cin>>nr;
  25.     // for(list<string>::iterator it2 = list1.begin(); it2!=list1.end(); it2++)
  26.     // cout<<*it2<<"\n";
  27.     int k=0;
  28.     list<string>::iterator it = list1.begin();
  29.  
  30. //     cout<<it;
  31.     while(list1.size()!=1)
  32.     {
  33.        // for(list<string>::iterator it = list1.begin(); it!=list1.end(); it++)
  34.         {
  35.             k++;
  36.            // it++;
  37.  
  38.             if(k==nr)
  39.             {
  40.  
  41.                 list2.push_back(*it);
  42.                 list1.erase(it);
  43.                 k=0;
  44.                 //  cout<<*it<<" ";
  45.             }
  46.             //  cout<<*it<<" ";
  47.  
  48.             //else
  49.                // k++;
  50.            // it++;
  51.             //   cout<<*it<<" ";
  52.             if((++it)==list1.end()) it=list1.begin();
  53.         }
  54.        // it=list1.begin();
  55.  
  56.  
  57.     }
  58.     cout<<"lista: \n";
  59.  
  60.     for(list<string>::iterator it3 = list1.begin(); it3!=list1.end(); it3++)
  61.         cout<<*it3<<"\n";
  62.  
  63.     cout<<"q: \n";
  64.     for(list<string>::iterator it2 = list2.begin(); it2!=list2.end(); it2++)
  65.         cout<<*it2<<"\n";
  66.  
  67.     return 0;
  68. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top