题目链接:http://codeforces.com/contest/1243/problem/B1
翻译:给一个字符串S,一个字符串T,长度均为n,问能否通过一次把Si跟Tj交换使得S与T相同
思路:找到两个不同的位置,(1)判断有没有第三个不同位置,若有输出NO(2)同一字符串在两个位置上的字符必须相等,是的话输出YES否则输出NO
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <cstring>
#include <algorithm>
#define ms(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
using namespace std;
const int maxn =1005;//提交记得修改
int a[maxn];
int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);//提交记得注释
int T;
cin>>T;
while(T--){
int n;
cin>>n;
string s,t;
cin>>s>>t;
int a=-1,b=-1;
int flag1=false;
for(int i=0;i<n;i++)
if(s[i]!=t[i]&&a==-1)a=i;
else if(s[i]!=t[i]&&b==-1)b=i;
else if(s[i]!=t[i]){
flag1=true;
break;
}
if(flag1){
cout<<"No"<<endl;
continue;
}
if(s[a]==s[b]&&t[b]==t[a])cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}