码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces Round #527 (Div3) C. Prefixes and Suffixes

时间:2018-12-27 15:40:23      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:space   first   tip   div   copy   exist   color   ==   cpp   

http://codeforces.com/contest/1092/problem/C

 

Ivan wants to play a game with you. He picked some string ss of length nn consisting only of lowercase Latin letters.

You don‘t know this string. Ivan has informed you about all its improper prefixes and suffixes (i.e. prefixes and suffixes of lengths from 11 to n?1n?1), but he didn‘t tell you which strings are prefixes and which are suffixes.

Ivan wants you to guess which of the given 2n?22n?2 strings are prefixes of the given string and which are suffixes. It may be impossible to guess the string Ivan picked (since multiple strings may give the same set of suffixes and prefixes), but Ivan will accept your answer if there is at least one string that is consistent with it. Let the game begin!

Input

The first line of the input contains one integer number nn (2n1002≤n≤100) — the length of the guessed string ss.

The next 2n?22n?2 lines are contain prefixes and suffixes, one per line. Each of them is the string of length from 11 to n?1n?1 consisting only of lowercase Latin letters. They can be given in arbitrary order.

It is guaranteed that there are exactly 22 strings of each length from 11 to n?1n?1. It is also guaranteed that these strings are prefixes and suffixes of some existing string of length nn.

Output

Print one string of length 2n?22n?2 — the string consisting only of characters ‘P‘ and ‘S‘. The number of characters ‘P‘ should be equal to the number of characters ‘S‘. The ii-th character of this string should be ‘P‘ if the ii-th of the input strings is the prefix and ‘S‘ otherwise.

If there are several possible answers, you can print any.

Examples
input
Copy
5
ba
a
abab
a
aba
baba
ab
aba
output
Copy
SPPSPSPS
input
Copy
3
a
aa
aa
a
output
Copy
PPSS
input
Copy
2
a
c
output
Copy
PS
Note

The only string which Ivan can guess in the first example is "ababa".

The only string which Ivan can guess in the second example is "aaa". Answers "SPSP", "SSPP" and "PSPS" are also acceptable.

In the third example Ivan can guess the string "ac" or the string "ca". The answer "SP" is also acceptable.

代码:

#include <bits/stdc++.h>
using namespace std;

int N;
vector<string> v;
vector<string> l1, l2;
string ans;

int main() {
    scanf("%d", &N);
    int cnt = 0;
    for(int i = 0; i < 2 * N - 2; i ++) {
        string s;
        cin >> s;
        v.push_back(s);
        if(s.size() == N - 1)
            l1.push_back(s);
    }

    string l = "";
    for(int i = 0; i < v.size(); i ++) 
        if(l1[0].substr(1, N - 2) == l1[1].substr(0, N - 2) && v[i] == l1[0].substr(0, v[i].size()))
            cnt ++;

    if(cnt >= N - 1) l = l1[0] + l1[1][N - 2];
    else l = l1[1] + l1[0][N - 2];


    map<int, int> mp;
    for(int i = 0; i < v.size(); i ++) {
        if(v[i] == l.substr(0, v[i].size()) && !mp[v[i].size()]) {
            ans += "P";
            mp[v[i].size()] ++;
        }
        else
            ans += "S";
    }

    cout << ans << endl;
    return 0;
}

  两个小时。。。改的想吐 口区!

CodeForces Round #527 (Div3) C. Prefixes and Suffixes

标签:space   first   tip   div   copy   exist   color   ==   cpp   

原文地址:https://www.cnblogs.com/zlrrrr/p/10184557.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!