Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
请帮忙看看,为什么一直wa#include "iostream" #include "string" #include "vector" #include "algorithm" using namespace std; int main() { int t,n,i,j,k,q; int m=0;//串长最小串的下标 vector<string> vs;//存放字符串数组 string s,base_string;//作为基准的字符串 string sub,sub_reverse;//子串 int max_sub_length=0; bool is_find; cin>>t; for(i=0;i<t;i++) { cin>>n; for(j=0;j<n;j++)//找最短串作为基准 { cin>>s; vs.push_back(s); if(j>0&&s.length()<vs[m].length()) m=j; } base_string=vs[m]; vs.erase(vs.begin()+m); for(j=0;j<base_string.length();j++) { for(k=base_string.length()-j;k>=1;k--)//长度应该由长到短 { if(k<=max_sub_length)break; sub=base_string.substr(j,k); sub_reverse=sub; reverse(sub_reverse.begin(),sub_reverse.end()); is_find=1; for(q=0;q<vs.size();q++) { if(vs[q].find(sub,0)==string::npos&&vs[q].find(sub_reverse,0)==string::npos) { is_find=0;break;//只要1个不匹配,其余不要再查找 } } if(is_find&&sub.length()>max_sub_length) { max_sub_length=sub.length(); } } } cout<<max_sub_length<<endl; vs.clear(); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator