题解 | #字符串字符匹配#
字符串字符匹配
https://www.nowcoder.com/practice/22fdeb9610ef426f9505e3ab60164c93
#include <stdio.h>
#include <string.h>
char shortstr[202]={'\0'};
char longstr[202]={'\0'};
int main() {
int a, b;
fgets(shortstr,202,stdin);
fgets(longstr,202,stdin);
int shlen=strlen(shortstr)-1;
int lolen=strlen(longstr)-1;
int low=0,fast=0,count=0;
while(shortstr[low]!='\n')
{
if(longstr[fast]!='\n')
{
if(shortstr[low]==longstr[fast])
{
count++;
low++;
fast=0;
// continue;
} else {
fast++;
}
} else {
low++;
fast=0;
}
}
if(count==shlen)
{
printf("true");
} else {
printf("false");
}
return 0;
}
测试自己的代码时多输入几组复杂点的测试用例,如果出错,可以做以下步骤检查:
1、迅速阅读代码,检查是否存在输入错误。尤其是涉及到判断条件的地方。
2、检查代码逻辑,看是否出现逻辑错误。
查看3道真题和解析
