Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct vertex
- {
- int next[300];
- bool leaf;
- };
- vertex t [210];
- int sz=1;
- string s;
- void add_string (const string & s)
- {
- int v = 0;
- for (size_t i=0; i<s.length(); ++i) {
- char c = s[i]-'a';
- if (t[v].next[c] == -1) {
- for (int i=0;i<29;++i)
- {
- t[sz].next[i]=-1;
- }
- t[v].next[c] = sz++;
- }
- v = t[v].next[c];
- }
- t[v].leaf = true;
- }
- bool pref(string s)
- {
- int v=0;
- for (int i=0;i<s.length();++i)
- {
- char c=s[i]-'a';
- if (t[v].next[c]==-1)
- {
- return false;
- }
- v=t[v].next[c];
- }
- return true;
- }
- int main()
- {
- int n,k,t;
- string a[200] ;
- cin>>t;
- for (int g=0;g<2*t-2;++g)
- {
- cin>>a[g];
- if (a[g].length()==t-1) s=a[g];
- }
- for (int i=0;i<29;++i)
- {
- t[0].next[i]=-1;
- }
- add_string(s);
- for (int g=0;g<2*t-2;++g)
- {
- if (pref(a[g])) {cout<<'P';} else {cout<<'S';}
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement