Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.31 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define uint int
  4.  
  5. using namespace std;
  6.  
  7. ifstream fin ("input.in");
  8. ofstream fout ("output.out");
  9.  
  10. string s;
  11. vector <string> word;
  12. vector <short> t;
  13. vector <vector<short>> l,m;
  14. short poz[1505];
  15. bitset<1505>a;
  16.  
  17. int main()
  18. {
  19.     getline(fin,s);
  20.  
  21.     for(uint i=0;i<s.size();++i)
  22.     {
  23.  
  24.         if(isalpha(s[i]))
  25.         {
  26.             bool ins=1;
  27.             string w="";
  28.             while(isalpha(s[i]))
  29.                 w+=s[i++];
  30.             --i;
  31.             for(uint j=0;j<word.size();++j)
  32.                 if(word[j]==w)
  33.                 {
  34.                     ins=0;
  35.                     break;
  36.                 }
  37.             if(ins)
  38.                 word.push_back(w);
  39.             t.push_back(word.size());
  40.         }
  41.     }
  42.     l.push_back(t);
  43.     t.clear();
  44.  
  45.     while(getline(fin,s))
  46.     {
  47.         int nc=0;
  48.         for(uint i=0;i<s.size();++i)
  49.         {
  50.  
  51.             if(isalpha(s[i]))
  52.             {
  53.                 ++nc;
  54.                 bool fnd=0;
  55.                 string w="";
  56.                 while(isalpha(s[i]))
  57.                     w+=s[i++];
  58.                 --i;
  59.                 for(uint j=0;j<word.size();++j)
  60.                     if(word[j]==w&&j+1==nc)
  61.                     {
  62.                         fnd=1;
  63.                         t.push_back(j+1);
  64.                         break;
  65.                     }
  66.                 if(!fnd)
  67.                     t.push_back(0);
  68.             }
  69.         }
  70.         l.push_back(t);
  71.         t.clear();
  72.     }
  73.     int pos=0;
  74.     bool kk=1;
  75.     for(int i=l.size()-1;i>=0&&kk;--i)
  76.         for(uint j=0;j<l[i].size()&&kk;++j)
  77.             if(l[i][j]!=0)
  78.             {
  79.                 pos=i;
  80.                 kk=0;
  81.             }
  82.  
  83.     for(uint j=0;j<l[pos].size();++j)
  84.         poz[l[pos][j]]=j;
  85.  
  86.     for(int i=0;i<l.size();++i)
  87.     {
  88.         for(uint j=0;j<l[i].size();++j)
  89.             cout<<l[i][j]<<" ";
  90.         cout<<"\n";
  91.     }
  92.  
  93.     for(int j=0;j<l[0].size();++j)
  94.     {
  95.         bool ok=0;
  96.         for(uint i=0;i<l.size();++i)
  97.         {
  98.  
  99.  
  100.             if(l[i][j]!=0&&poz[l[i][j]]==j)
  101.             {
  102.                 t.push_back(i);
  103.                 if(i==pos)
  104.                     ok=1;
  105.  
  106.             }
  107.         }
  108.         if(ok)
  109.             m.push_back(t);
  110.         t.clear();
  111.     }
  112.  
  113.  
  114.  
  115.     return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement