想法
用cstring的strstr函数可以解决
strstr函数的用法
strstr(a,b),如b不是a的子串,返回NULL
上代码
#include<iostream>
#include<cstring>
using namespace std;
int main(){
char a[20],b[20];
cin>>a>>b;
if(strstr(a,b)!=NULL){//如b是a的子串
cout<<b<<" is substring of "<<a;
}else if(strstr(b,a)!=NULL){//如a是b的子串
cout<<a<<" is substring of "<<b;
}else{//如都不是
cout<<"No substring";
}
return 0;
}