题目链接:Problem - 1092C - Codeforces
C. Prefixes and Suffixes
我的思路:
1、提取出长度为(n-1)的子串,然后将其拼接出原串
2、判断子串能否成为 Prefixes
3、输出结果
WA代码:
(Wrong Answer on test 19)
#include <iostream>
#include <cstdio>
#include <string>
using namespace std ;
const int N = 1e4+10 ;
string ss , s[N] , maxx[N] ;
bool p[N] = { false } , judge[N]={ false };
int main()
{
int n ;
cin >> n ;
for(int i=1 ; i<=2*n-2 ; ++i ) cin >> s[i] ;
//特例:n = 2 时, PS
if(n == 2){
cout << "PS" << '\n' ; return 0 ;
}
int flag = 0 ;
for(int i=1 ; i<=2*n-2 ; ++i )
if(s[i].size() == n-1) maxx[++flag] = s[i] ;
// 判断ss
string mid = maxx[1].substr(1 , n-2) ;
if(maxx[2].find(mid) == 0) ss = maxx[1] + maxx[2][n-2] ;
else ss = maxx[2] + maxx[1][n-2] ;
for(int i=1 ; i<=2*n-2 ; ++i )
if(ss.find(s[i])==0 && !judge[s[i].size()]){
judge[s[i].size()] = true ;
p[i] = true ;
}
for(int i=1 ; i <= 2*n-2 ; ++i)
{
if(p[i]) cout << 'P' ;
else cout << 'S' ;
}
cout << '\n' ;
system("pause") ;
return 0 ;
}
临表涕零,感激不尽!
原文链接:https://blog.csdn.net/2301_79379567/article/details/135773364