Codeforces Round #599 (Div. 2) B1. Character Swap (Easy Version)
This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems.
After struggling and failing many times, Ujan decided to try to clean up his house again. He decided to get his strings in order first.
Ujan has two distinct strings ss and tt of length nn consisting of only of lowercase English characters. He wants to make them equal. Since Ujan is lazy, he will perform the following operation exactly once: he takes two positions ii and jj (1≤i,j≤n1≤i,j≤n, the values ii and jj can be equal or different), and swaps the characters sisi and tjtj. Can he succeed?
Note that he has to perform this operation exactly once. He has to perform this operation.
The first line contains a single integer kk (1≤k≤101≤k≤10), the number of test cases.
For each of the test cases, the first line contains a single integer nn (2≤n≤1042≤n≤104), the length of the strings ss and tt.
Each of the next two lines contains the strings ss and tt, each having length exactly nn. The strings consist only of lowercase English letters. It is guaranteed that strings are different.
For each test case, output "Yes" if Ujan can make the two strings equal and "No" otherwise.
You can print each letter in any case (upper or lower).
4
5
souse
houhe
3
cat
dog
2
aa
az
3
abc
bca
Yes
No
No
No
In the first test case, Ujan can swap characters s1s1 and t4t4, obtaining the word "house".
In the second test case, it is not possible to make the strings equal using exactly one swap of sisi and tjtj.
#include<bis/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d",&t);
while(t--) {
int n;
scanf("%d",&n);
string s,t;
cin>>s;
cin>>t;
int c1=-,c2=-;
int flag = ;
int sum=;
for(int i = ; i < n; i++) {
if(s[i] != t[i]) {
sum++;
if(sum == ) { //记录不同的位置
c1 = i;
} else if(sum == ) {
c2 = i;
} else {
flag = ;//两对以上,直接结束
break;
}
}
}
if(flag == ) {
printf("No\n");
continue;
}
if(s[c1] == s[c2]&&t[c1] == t[c2]) {
printf("Yes\n");
} else {//字母不同
printf("No\n");
}
}
return ;
}
Codeforces Round #599 (Div. 2) B1. Character Swap (Easy Version)的更多相关文章
- Codeforces Round #599 (Div. 2) B1. Character Swap (Easy Version) 水题
B1. Character Swap (Easy Version) This problem is different from the hard version. In this version U ...
- Codeforces Round #599 (Div. 2) B2. Character Swap (Hard Version) 构造
B2. Character Swap (Hard Version) This problem is different from the easy version. In this version U ...
- Codeforces Round #599 (Div. 2) B2. Character Swap (Hard Version)
This problem is different from the easy version. In this version Ujan makes at most 2n2n swaps. In a ...
- Codeforces Round #540 (Div. 3) F1. Tree Cutting (Easy Version) 【DFS】
任意门:http://codeforces.com/contest/1118/problem/F1 F1. Tree Cutting (Easy Version) time limit per tes ...
- Codeforces Round #540 (Div. 3)--1118F1 - Tree Cutting (Easy Version)
https://codeforces.com/contest/1118/problem/F1 #include<bits/stdc++.h> using namespace std; in ...
- Codeforces Round #653 (Div. 3) E1. Reading Books (easy version) (贪心,模拟)
题意:有\(n\)本书,A和B都至少要从喜欢的书里面读\(k\)本书,如果一本书两人都喜欢的话,那么他们就可以一起读来节省时间,问最少多长时间两人都能够读完\(k\)本书. 题解:我们可以分\(3\) ...
- Codeforces Round #672 (Div. 2) C1. Pokémon Army (easy version) (DP)
题意:给你一组数\(a\),构造一个它的子序列\(b\),然后再求\(b_1-b2+b3-b4...\),问构造后的结果最大是多少. 题解:线性DP.我们用\(dp1[i]\)来表示在\(i\)位置, ...
- Codeforces Round #650 (Div. 3) F1. Flying Sort (Easy Version) (离散化,贪心)
题意:有一组数,每次操作可以将某个数移到头部或者尾部,问最少操作多少次使得这组数非递减. 题解:先离散化将每个数映射为排序后所对应的位置,然后贪心,求最长连续子序列的长度,那么最少的操作次数一定为\( ...
- Codeforces Round #658 (Div. 2) C1. Prefix Flip (Easy Version) (构造)
题意:给你两个长度为\(n\)的01串\(s\)和\(t\),可以选择\(s\)的前几位,取反然后反转,保证\(s\)总能通过不超过\(3n\)的操作得到\(t\),输出变换总数,和每次变换的位置. ...
随机推荐
- (转)Android访问webservice
纠正网上乱传的android调用Webservice方法. 1.写作背景: 笔者想实现android调用webservice,可是网上全是不管对与错乱转载的文章,结果不但不能解决问题,只会让人心烦 ...
- python之爬虫(爬取.ts文件并将其合并为.MP4文件——以及一些异常的注意事项)
//20200115 最近在看“咱们裸熊——we bears”第一季和第三季都看完了,单单就第二季死活找不到,只有腾讯有资源,但是要vip……而且还是国语版……所以就瞄上了一个视频网站——可以在线观看 ...
- 小I的小姐姐
小 I 的小姐姐 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 小 I 去天津玩啦,一路上,他跟他的同学发生了许多有趣 ...
- gz、tar、zip、bz2压缩和解压缩命令
gzip 压缩后的格式为:*.gz 这种压缩方式不能保存原文件:且不能压缩目录 命令举例:#压缩[root@localhost tmp]# gzip buodo[root@localhost tmp] ...
- 并查集-E - Wireless Network
E - Wireless Network An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical t ...
- windows 10 安装使用kafka
1.安装java环境 自行百度 2. 下载.安装Kafka 打开 下载地址 http://kafka.apache.org/downloads.html 下载二进制文件 Kafka包名组成: Scal ...
- Hog实例
1.计算Hog的特征得维度: #include <iostream> #include <opencv2/core/core.hpp> #include <opencv2 ...
- 谷歌浏览器安装apizza
接口测试是卡发中不可缺少的一环,那么常用的postman是英文就很不方便一些小伙伴的使用,所以此工具和postman功能相同且升级并且是中文模式 安装: 链接:https://pan.baidu.co ...
- mysql 对数据的自增ID重新进行排序
创建表格时添加: create table table1(id int auto_increment primary key,...) 创建表格后添加: 删除原有主键: ALTER TABLE `ta ...
- centos7添加搜狗输入法
https://www.cnblogs.com/eeexu123/p/9259430.html https://blog.csdn.net/jpch89/article/details/8190380 ...