Advertisement
Alexandre_lsv

Untitled

Mar 20th, 2016
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. typedef long long ll;
  3. typedef long double ld;
  4. using namespace std;
  5.  
  6.  
  7. set<string> findMax(set<string> gens, set<string>::iterator itt){
  8.     set<string> res;
  9.     res=gens;
  10.     set<string>::iterator it = itt;
  11.     string s = *it;
  12.     if (itt==gens.end()){
  13.         set<string> ss;
  14.         ss = gens;
  15.         ss.erase(*gens.begin());
  16.         ss.erase(*(gens.begin()+1);
  17.         string t=(*(gens.begin()+1))+(*gens.begin());
  18.         ss.insert(t);
  19.         cout << t << '-' << endl;
  20.         res = findMax(ss, ss.begin()); 
  21.     }
  22.     bool b=false;
  23.     for (ll i=1; i<s.length(); i++){
  24.         for (auto&gen:gens){
  25.             if ((gen!=s)&&(gen.find(s.substr(i))==0)){
  26.                 b=true;
  27.                 set<string> ss;
  28.                 ss = gens;
  29.                 ss.erase(gen);
  30.                 ss.erase(s);
  31.                 string t=s+gen.substr(i);
  32.                 ss.insert(t);
  33.                 cout << t << '-' << endl;
  34.                 res = findMax(ss, ss.begin());
  35.             }
  36.         }
  37.         if (b)
  38.             break;
  39.     }
  40.     if (!b)
  41.         res=findMax(gens, it++);
  42.     return res;
  43. }
  44.  
  45.  
  46. int main()
  47. {
  48.     cin.sync_with_stdio(false);
  49.     cout.sync_with_stdio(false);
  50.    ll n, a;
  51.    cin >> n;
  52.    string s;
  53.    set<string> gens;
  54.     for (ll i=0; i<n; i++){
  55.         cin >> s;
  56.         gens.insert(s);
  57.    }
  58.    set<string> del;
  59.    set<string>::iterator it = gens.begin();
  60.    while (it != gens.end()){
  61.         set<string>::iterator jt=gens.begin();
  62.          while (jt != gens.end()){
  63.             if ((jt!=it)&&((*it).find(*jt) != std::string::npos))
  64.                 del.insert(*jt);
  65.                 //gens.erase(*jt);             
  66.         jt++;
  67.         }
  68.         it++;
  69.     }
  70.  
  71.     /*for (auto&d:del)
  72.         gens.erase(d);
  73.     for (auto&gen:gens)
  74.         cout << gen << endl;
  75. */
  76.  
  77.     set<string> res;
  78.     res = findMax(gens, gens.begin());
  79.  
  80.     for (auto&gen:gens)
  81.         cout << gen << endl;
  82.  
  83.  
  84.    return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement