题解 | #字符串字符匹配#
字符串字符匹配
https://www.nowcoder.com/practice/22fdeb9610ef426f9505e3ab60164c93
#include <stdio.h> #include <string.h> int main() { char S[400]; char T[410]; while (scanf("%s %s", S, T) != EOF) { int lenS = strlen(S); int lenT = strlen(T); int i,j; int count = 0;; for(i=0;i<lenS;i++) { for(j=0;j<lenT;j++) { if(S[i] == T[j]) { count++; i++; //防止T字符串中有与T[j]相同的字符,造成count的偏大,所以只要一个相同的值就行 j = 0; //直接i++后从0开始遍历 } } } if(count == lenS) printf("true"); else printf("false"); } return 0; }