题解 | #字符串字符匹配#
字符串字符匹配
https://www.nowcoder.com/practice/22fdeb9610ef426f9505e3ab60164c93
#include <stdio.h>
int main() {
int a, b,st,c,e,f;
char str1[200]={'\0'};
char str2[200]={'\0'};
gets(str1);
a=strlen(str1);
gets(str2);
b=strlen(str2);
st=0; //短
f=0; //错误计数
while(st<a)
{
e=1;
for(c=0;c<b;c++)
{
if(str1[st]==str2[c])
continue;
else e++; //未出现过,必然在字符长度b后依旧无,值为b+1
}
if(e>b)
{
printf("false");
f++;
break;//一个不匹配就计数,并结束运行
}
st++;
}
if(f==0) // 已经输出false,就不再运行该语句
printf("true");
return 0;
}

查看11道真题和解析