Codeforces Round #599 (Div. 2) B1

题目链接: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;
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值