求教
查看原帖
求教
1237804
thomas1234567楼主2024/6/23 11:36

#include<bits/stdc++.h> using namespace std; string s1; string s2; void find_str(string x,string y) { int len = x.size(); for(int i=0;i<len;i++) { if(x[i]==y[0]) { if(y.size()+1-1>=len) { continue; } string ans=""; ans=x.substr(i,y.size()); if(ans==y) { cout<<y<<" is substring of " << x; return ; } } } cout<<"No substring"; } int main() { cin>>s1>>s2; if(s1.size()>s2.size()) { find_str(s1,s2); } else { find_str(s2,s1); } }``` #include<bits/stdc++.h> using namespace std; string s1; string s2; void find_str(string x,string y) { int len = x.size(); for(int i=0;i<len;i++) { if(x[i]==y[0]) { if(y.size()+1-1>=len) { continue; } string ans=""; ans=x.substr(i,y.size()); if(ans==y) { cout<<y<<" is substring of " << x; return ; } } } cout<<"No substring"; } int main() { cin>>s1>>s2; if(s1.size()>s2.size()) { find_str(s1,s2); } else { find_str(s2,s1); } }

2024/6/23 11:36
加载中...