标签:cout div class flag 字母 src out 输入数据 panel
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2720 Accepted Submission(s):
893
#include<cstdio> #include<cstring> #include<string> #include<iostream> using namespace std; int main(){ string s,s1,s2,s3,str; int t; scanf("%d",&t); getchar(); while(t--){ cin>>s1>>s2>>s3; str=s1+"#"; int len=s1.length(); for(int i=0;i<len;i++){ for(int j=i+1;j<=len;j++){ s=s1.substr(i,j-i);//c++函数,把s1字符串的第i个到第j-i个赋给c; if(s.find(s2)!=-1&&s.find(s3)!=-1){//等于-1表示没有; if(str.length()>s.length()){ str=s; }else{ if(str>s){ str=s; } } } } } if(str.length()==len+1){ printf("No\n"); }else{ cout<<str<<endl; } } return 0; }
#include<iostream> #include<string> #include<cstring> #include<algorithm> using namespace std; struct node{ string str; int len; }k[11000]; bool cmp(node x,node y){ if(x.len==y.len){ return x.str<y.str; }else{ return x.len<y.len; } } int main(){ string s1,s2,s3; int t; cin>>t; while(t--){ cin>>s1>>s2>>s3; int cnt=0,flag=0; for(int i=0;s1[i];i++){ for(int j=i;s1[j];j++){ string c; for(int q=i;q<=j;q++){ c+=s1[q]; } if(c.find(s2)!=-1&&c.find(s3)!=-1){ k[cnt].str=c; k[cnt].len=c.size(); cnt++; flag=1; break; } } } if(flag==0){ cout<<"No"<<endl; }else{ sort(k,k+cnt,cmp); cout<<k[0].str<<endl; } } return 0; }
标签:cout div class flag 字母 src out 输入数据 panel
原文地址:https://www.cnblogs.com/qqshiacm/p/10821860.html