Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
3429 | 邓小龙 | 字符串包含判断 | C++ | Accepted | 0 MS | 268 KB | 1166 | 2024-06-07 21:20:42 |
# include<iostream> # include<cstring> using namespace std; string a,b; void fun(){//不用函数解题 int lena=a.size(),lenb=b.size(); for(int i=0;i<lena-lenb;i++){ bool f=0;//标记是否包含,==0代表包含 if(a[i]==b[0]){ for(int j=i,k=0;k<lenb;j++,k++){ if(a[j]!=b[k]) {f=1;break;}//f==1代表不包含 } if(f==0){ cout<<"yes"<<endl; return; } } } cout<<"no"<<endl; } void fun1(){//使用a.find(b)解题 if(a.find(b)<=(a.size()-b.size())) cout<<"yes"<<endl; else cout<<"no"<<endl; } void fun2(){//利用substr解题 string c; int lena=a.size(),lenb=b.size(); for(int i=0;i<lena-lenb;i++){ c=a.substr(i,lenb); if(c==b){ cout<<"yes"<<endl; return; } } cout<<"no"<<endl; } int main(){ getline(cin,a); getline(cin,b); //cout<<a.find(b)<<endl; //cout<<a.substr(2,3)<<endl;//如果第二个参数超出了a字符串,则只输出a有的部分 fun2(); return 0; }