Run ID:3471
提交时间:2024-06-08 17:26:20
# include<iostream> #include<string> using namespace std; string s1,s2; //思路:遍历字符串s1,从第一位开始,找s2长度的字符串,然后去比较s1的子串=s2 void fun(){ int len_s1=s1.size(), len_s2=s2.size(); for(int i=0;i<len_s1-len_s2;i++){ bool f=1;//默认为1,代表a中包含b for(int j=i,k=0;k<len_s2;j++,k++){ if(s1[j]!=s2[k]) {f=0;break;} } if(f) {cout<<"yes"<<endl; return;} } cout<<"no"<<endl; } void fun2(){ int t=s1.find(s2); if(t<s1.size()&&t>=0) cout<<"yes"<<endl; else cout<<"no"<<endl; } //s1.find(s2):寻找s1中第一次出现s2的位置 int main(){ getline(cin,s1); getline(cin,s2); fun2(); return 0; }