救命 c选手苦苦思索为什么第一个和第三个过不了 求助大佬们
查看原帖
救命 c选手苦苦思索为什么第一个和第三个过不了 求助大佬们
945418
unbelievable_cheese楼主2023/2/19 18:03
#include <stdio.h>
#include <string.h>

int main() {
	char s1[20], s2[20];
	int i, j, l1, l2, count = 0, flag = 0;
	gets(s1);
	gets(s2);
	l1 = strlen(s1);
	l2 = strlen(s2);
	if (l1 >= l2) {
		for (i = 0; i < l1; i++) {
			if (s2[0] == s1[i]) {
				for (j = 0; j < l2; j++) {
					if (s1[j + i] == s2[j])
						count++;
					else
						break;
				}
			}
			if (count == (l2 )) {
				flag = 1;
				printf("%s is substring of %s", s2, s1);
				break;
			} else {
				count = 0;
			}
		}
	} else if (l1 < l2) {
		for (i = 0; i < l2; i++) {
			if (s1[0] == s2[i]) {
				for (j = 0; j < l1; j++) {
					if (s2[j + i] == s1[j])
						count++;
					else
						break;
				}
			}
			if (count == (l1 )) {
				flag = 1;
				printf("%s is substring of %s", s1, s2);
				break;
			} else {
				count = 0;
			}

		}
	}
	if (flag == 0) {
		printf("No substring");
	}
	return 0;
}

2023/2/19 18:03
加载中...