Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.09 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4. #include <cstdio>
  5. #include <string>
  6. #include <cmath>
  7. #include <ctime>
  8. #include <queue>
  9. #include <map>
  10.  
  11. using namespace std;
  12.  
  13. //constants
  14. const int MAXN=(int)(1e5+1e1);
  15. const double PI=acos(-1.0);
  16.  
  17. //defines
  18. #define ll long long
  19. #define TASKNAME "."
  20. #define fr freopen(TASKNAME"in","r",stdin);
  21. #define fw freopen(TASKNAME"out","w",stdout);
  22. #define mp make_pair
  23. #define pb push_back
  24. #define F first
  25. #define S second
  26. #define eof (-1)
  27. #define forr(xx,yy,zz) for(int zz=xx;zz<=yy;zz++)
  28. #define forl(xx,yy,zz) for(int zz=xx;zz>=yy;zz--)
  29. #define sqr(x) ((x)*(x))
  30. #define sz(x) (int)x.size()
  31. #define mod 10000000007
  32. #define len(s) (int)(s.length())
  33. #define all(a) a.begin(),a.end()
  34. //=
  35.  
  36. int n,k;
  37. string s,t,q;
  38. vector<pair<string,vector<string> > > ans;
  39.  
  40.  
  41. int main()
  42. {
  43.     ios_base::sync_with_stdio(false);
  44.     cin.tie(0);
  45.     cin >> n;
  46.     forr(1,n,i)
  47.     {
  48.         cin >> s >> k;
  49.         int g=-1;
  50.         forr(0,sz(ans)-1,j)
  51.         {
  52.             if(ans[j].F==s)
  53.             {
  54.                 g = j;
  55.                 break;
  56.             }
  57.         }
  58.         if(g==-1)
  59.         {
  60.             ans.pb(mp(s,0));
  61.             g = ans.size()-1;
  62.         }
  63.         forr(1,k,j)
  64.         {
  65.             cin >> q;
  66.             ans[g].S.pb(q);
  67.         }
  68.     }
  69.     GGG:
  70.     forr(0,sz(ans)-1,i)
  71.     {
  72.         forr(0,sz(ans[i].S)-1,j)
  73.         {
  74.             forr(j+1,sz(ans[i].S)-1,z)
  75.             {
  76.                 if(len(ans[i].S[j])>=len(ans[i].S[z]))
  77.                 {
  78.                     if(ans[i].S[j].substr(len(ans[i].S[j])-len(ans[i].S[z]),len(ans[i].S[z]))==ans[i].S[z])
  79.                     {
  80.                     //  myvector.erase (myvector.begin()+5)
  81.  
  82.                     //  cout << ans[i].S[z] << ' ' << ans[i].S[j] << '\n';
  83.                         ans[i].S.erase(ans[i].S.begin()+z);
  84.                         goto GGG;
  85.                     }
  86.                 }
  87.                 else
  88.                 {
  89.                     if(ans[i].S[z].substr(len(ans[i].S[z])-len(ans[i].S[j]),len(ans[i].S[j]))==ans[i].S[j])
  90.                     {
  91.                     //  myvector.erase (myvector.begin()+5)
  92.  
  93.                     //  cout << ans[i].S[z] << ' ' << ans[i].S[j] << '\n';
  94.                         ans[i].S.erase(ans[i].S.begin()+j);
  95.                         goto GGG;
  96.                 }
  97.                 }
  98.             }
  99.         }
  100.     }
  101.  
  102.  
  103.     cout<< sz(ans) << '\n';
  104.     forr(0,sz(ans)-1,i)
  105.     {
  106.         cout << ans[i].F << ' '<<sz(ans[i].S) << ' ';
  107.         forr(0,sz(ans[i].S)-1,j)
  108.             cout << ans[i].S[j]<< ' ';
  109.         cout << '\n';
  110.     }
  111.     return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement