Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define uint int
- using namespace std;
- ifstream fin ("input.in");
- ofstream fout ("output.out");
- string s;
- vector <string> word;
- vector <short> t;
- vector <vector<short>> l,m;
- short poz[1505];
- bitset<1505>a;
- int main()
- {
- getline(fin,s);
- for(uint i=0;i<s.size();++i)
- {
- if(isalpha(s[i]))
- {
- bool ins=1;
- string w="";
- while(isalpha(s[i]))
- w+=s[i++];
- --i;
- for(uint j=0;j<word.size();++j)
- if(word[j]==w)
- {
- ins=0;
- break;
- }
- if(ins)
- word.push_back(w);
- t.push_back(word.size());
- }
- }
- l.push_back(t);
- t.clear();
- while(getline(fin,s))
- {
- int nc=0;
- for(uint i=0;i<s.size();++i)
- {
- if(isalpha(s[i]))
- {
- ++nc;
- bool fnd=0;
- string w="";
- while(isalpha(s[i]))
- w+=s[i++];
- --i;
- for(uint j=0;j<word.size();++j)
- if(word[j]==w&&j+1==nc)
- {
- fnd=1;
- t.push_back(j+1);
- break;
- }
- if(!fnd)
- t.push_back(0);
- }
- }
- l.push_back(t);
- t.clear();
- }
- int pos=0;
- bool kk=1;
- for(int i=l.size()-1;i>=0&&kk;--i)
- for(uint j=0;j<l[i].size()&&kk;++j)
- if(l[i][j]!=0)
- {
- pos=i;
- kk=0;
- }
- for(uint j=0;j<l[pos].size();++j)
- poz[l[pos][j]]=j;
- for(int i=0;i<l.size();++i)
- {
- for(uint j=0;j<l[i].size();++j)
- cout<<l[i][j]<<" ";
- cout<<"\n";
- }
- for(int j=0;j<l[0].size();++j)
- {
- bool ok=0;
- for(uint i=0;i<l.size();++i)
- {
- if(l[i][j]!=0&&poz[l[i][j]]==j)
- {
- t.push_back(i);
- if(i==pos)
- ok=1;
- }
- }
- if(ok)
- m.push_back(t);
- t.clear();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement