Advertisement
Saleh127

UVA 122 / Implementation

Aug 8th, 2022
885
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | None | 0 0
  1. /***
  2.  created: 2022-08-08-21.25.18
  3. ***/
  4.  
  5. #include <bits/stdc++.h>
  6. #include <ext/pb_ds/assoc_container.hpp>
  7. #include <ext/pb_ds/tree_policy.hpp>
  8. using namespace std;
  9. using namespace __gnu_pbds;
  10. template<typename U> using ordered_set=tree<U, null_type,less<U>,rb_tree_tag,tree_order_statistics_node_update>;
  11. #define ll long long
  12. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  13. #define get_lost_idiot return 0
  14. #define nl '\n'
  15.  
  16. struct st
  17. {
  18.     string p,v;
  19.  
  20. } a[2220];
  21.  
  22. bool cmp(st b,st c)
  23. {
  24.     if(b.p.size()==c.p.size()) return b.p<c.p;
  25.     else return b.p.size()<c.p.size();
  26.  
  27. }
  28.  
  29. set<string>x;
  30.  
  31. int main()
  32. {
  33.     ios_base::sync_with_stdio(0);
  34.     cin.tie(0);
  35.     cout.tie(0);
  36.  
  37.     string s;
  38.  
  39.     while(cin>>s && s!="12")
  40.     {
  41.         x.clear();
  42.  
  43.         ll n,m,i,j,k,l=0;
  44.  
  45.         n=0;
  46.  
  47.         while(s[1]!=')')
  48.         {
  49.             ll j=1;
  50.  
  51.             string p="",v="";
  52.  
  53.             while(s[j]!=',')
  54.             {
  55.                 v+=s[j];
  56.                 j++;
  57.             }
  58.             while(s[j]!=')')
  59.             {
  60.                 p+=s[j];
  61.                 j++;
  62.             }
  63.             a[n].p=p;
  64.             a[n].v=v;
  65.             n++;
  66.             cin>>s;
  67.         }
  68.  
  69.  
  70.         sort(a,a+n,cmp);
  71.  
  72.         for(i=0; i<n; i++)
  73.         {
  74.             if(x.count(a[i].p))
  75.             {
  76.                 l=1;
  77.                 break;
  78.             }
  79.  
  80.             if(a[i].p.size()>1)
  81.             {
  82.                 if(!x.count(a[i].p.substr(0,a[i].p.size()-1)))
  83.                 {
  84.                     l=1;
  85.                     break;
  86.                 }
  87.             }
  88.  
  89.             x.insert(a[i].p);
  90.         }
  91.         if(l) cout<<"not complete"<<nl;
  92.         else
  93.         {
  94.             for(i=0; i<n; i++)
  95.             {
  96.                 cout<<a[i].v;
  97.  
  98.                 if(i<n-1) cout<<" ";
  99.                 else cout<<nl;
  100.             }
  101.         }
  102.     }
  103.  
  104.     get_lost_idiot;
  105. }
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement