3063101_ac_78ms_304k.c

来自「北大大牛代码 1240道题的原代码 超级权威」· C语言 代码 · 共 63 行

C
63
字号
#include <stdio.h>
#include <string.h>

int main()
{
	int n, c;
	int i, j;
	int l1, l2;
	char str1[202], str2[202], str3[402];
	int array[202][202];

	scanf("%d",&n);
	for (c = 1; c <= n; c++)
	{
		printf("Data set %d: ",c);
		scanf("%s%s%s",str1,str2,str3);
		l1 = strlen(str1);
		l2 = strlen(str2);
		array[0][0] = 1;
		for(i = 1; i <= l1; i++)
		{
			if(str1[i-1]==str3[i-1])
			{
				array[0][i] = 1;
			}
			else
			{
				while(i <= l1)
				{
					array[0][i++] = 0;
				}
			}
		}
		for(j = 1; j <= l2; j++)
		{
			if(str2[j-1]==str3[j-1])
			{
				array[j][0] = 1;
			}
			else
			{
				while(j <= l2)
				{
					array[j++][0] = 0;
				}
			}
		}
		for(i = 1; i <= l2; i++)
		{
			for(j = 1; j <= l1; j++)
			{
				if (array[i][j-1]&&str1[j-1]==str3[i+j-1]||array[i-1][j]&&str2[i-1]==str3[i+j-1])
				{
					array[i][j] = 1;
				}
				else
					array[i][j] = 0;
			}
		}
		puts(array[l2][l1]?"yes":"no");
	}
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?