标签:include span before 题目 sample std led 字符串 实现
#include<iostream> #include<string> #include<algorithm> using namespace std; string matched_Prefix_Postfix(string s) { int slength=s.size(); string before[slength-1]; string after[slength-1]; for(int i=0;i<slength-1;i++) { before[i]=s.substr(0,i); } reverse(s.begin(),s.end()); for(int i=0;i<slength-1;i++) { after[i]=s.substr(0,i); reverse(after[i].begin(),after[i].end()); } reverse(s.begin(),s.end()); int Max=0; int index=-1; for(int i=0;i<slength-1;i++) { for(int j=0;j<slength-1;j++) { if(before[i]==after[j]) { int t=after[i].size(); if(t>Max) { index=i; Max=t; } } } } if(Max==0) { string e="empty"; return e; } else { string f=before[index]; return f; } } int main() { int T; cin>>T; while(T--) { string s; cin>>s; cout<<matched_Prefix_Postfix(s)<<endl; } return 0; }
标签:include span before 题目 sample std led 字符串 实现
原文地址:https://www.cnblogs.com/SZU-DS-wys/p/12180767.html