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

# define MaxSize 10010

char line_0[MaxSize];
char line_1[MaxSize];

int main()
{
	int k;
	int n;
	scanf("%d", &k);
	while(k--)
	{
		int Count=0;
		memset(line_0, 0, sizeof(char)*MaxSize);
		memset(line_1, 0, sizeof(char)*MaxSize);
		scanf("%d", &n);
		getchar();
		scanf("%s", line_0);
		scanf("%s", line_1);
		int i;
		int flag_0=0, flag_1=0;
		for(i=0; i<n; ++i)
		{
			if(line_0[i]!=line_1[i])
			{
				++Count;
				if(Count==1)
					flag_0=i;
				else
					flag_1=i;
			}
			if(Count>2)
				break;
		}
		if(Count==2)
		{
			if((line_0[flag_0]==line_0[flag_1])&&(line_1[flag_0]==line_1[flag_1]))
				printf("YES\n");
			else
				printf("NO\n");
		}
		else
			printf("NO\n");
	}
	return 0;
}

  @这道题能满足输出结果为"YES"的只有一种情况:两个字符串对应位置比较是否相同时,只能有两处不同,并且对于每个字符串在比较时出现的两个不同处的字母必须相同。

 posted on 2019-11-07 11:56  ComMario  阅读(170)  评论(0编辑  收藏  举报