题目:10340 - All in All


题目大意:给出字符串s和t,问s是否是t的子串。s若去掉某些字符能和t一样,那么t是s的子串。


解题思路:匹配字符。t的每一个字符和s中的字符匹配。注意这里的字符数组大小要开大点。


代码:

#include <stdio.h>
#include <string.h>

const int N = 1000005;
char s[N], t[N];

bool match () {
	
	int i = 0;
	int lens = strlen(s);
	int lent = strlen(t);
	for (int j = 0; j < lent; j++) {
		
		if (i == lens)
			return true;
		if (lens - i > lent - j)
			return false;
		if (s[i] == t[j])
			i++;
	}
	if (i == lens)
		return true;
	return false;
}

int main () {
	
	while (scanf ("%s", s) != EOF) {

		scanf ("%s", t);
		printf ("%s\n", match()? "Yes" :"No");
	}
	return 0;
}


相关文章:

  • 2022-12-23
  • 2021-08-12
  • 2022-12-23
  • 2021-08-31
  • 2021-10-17
  • 2021-12-03
  • 2022-12-23
  • 2021-07-28
猜你喜欢
  • 2021-12-13
  • 2022-02-28
  • 2022-12-23
  • 2022-12-23
  • 2021-06-25
相关资源
相似解决方案