CodeForces - 186A-Comparing Strings
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not.
Input
The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length.
Output
Print "YES", if the dwarves belong to the same race. Otherwise, print "NO".
Examples
Input
ab
ba
Output
YES
Input
aa
ab
Output
NO
Note
- First example: you can simply swap two letters in string "ab". So we get "ba".
- Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".
题解:题目大意是让你判断是否能通过换两个字母的位置是否一样
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
char s1[100005],s2[100005];
scanf("%s%s",s1,s2);
int flag=0;
int a[100005];
int temp=0;
for(int t=0;t<strlen(s1);t++)
{
if(strlen(s1)!=strlen(s2))
{
flag=3;
}
if(s1[t]!=s2[t])
{
a[temp]=t;
temp++;
flag++;
if(flag==3)
break;
}
else
continue;
}
if(flag==2)
{
if(s1[a[0]]==s2[a[1]]&&s1[a[1]]==s2[a[0]])
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
else
{
printf("NO\n");
}
return 0;
}
CodeForces - 186A-Comparing Strings的更多相关文章
- Codeforces 868D Huge Strings - 位运算 - 暴力
You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed ...
- codeforces 112APetya and Strings(字符串水题)
A. Petya and Strings 点击打开题目 time limit per test 2 seconds memory limit per test 256 megabytes input ...
- [Codeforces Round #438][Codeforces 868D. Huge Strings]
题目链接:868D - Huge Strings 题目大意:有\(n\)个字符串,\(m\)次操作,每次操作把两个字符串拼在一起,并询问这个新串的价值.定义一个新串的价值\(k\)为:最大的\(k\) ...
- [Educational Round 5][Codeforces 616F. Expensive Strings]
这题调得我心疲力竭...Educational Round 5就过一段时间再发了_(:з」∠)_ 先后找了三份AC代码对拍,结果有两份都会在某些数据上出点问题...这场的数据有点水啊_(:з」∠)_[ ...
- Codeforces 559B - Equivalent Strings
559B - Equivalent Strings 思路:字符串处理,分治 不要用substr(),会超时 AC代码: #include<bits/stdc++.h> #include&l ...
- Codeforces 112A-Petya and Strings(实现)
A. Petya and Strings time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- CodeForces - 985F Isomorphic Strings
假如两个区间的26的字母出现的位置集合分别是 A1,B1,A2,B2,....., 我们再能找到一个排列p[] 使得 A[i] = B[p[i]] ,那么就可以成功映射了. 显然集合可以直接hash, ...
- [Codeforces 452E] Three Strings
[题目链接] https://codeforces.com/contest/452/problem/E [算法] 构建后缀数组 用并查集合并答案即可 时间复杂度 : O(NlogN) [代码] #in ...
- Codeforces 665C Simple Strings【暴力,贪心】
题目链接: http://codeforces.com/contest/665/problem/C 题意: 改变最少的字符,使得最终序列无相同的连续的字符. 分析: 对每一个与前一个字符相同的字符,枚 ...
- Codeforces - 559B - Equivalent Strings - 分治
http://codeforces.com/problemset/problem/559/B 这个题目,分治就好了,每次偶数层可以多一种判断方式,判断它的时间就是logn的(吧),注意奇数层并不是直接 ...
随机推荐
- bzoj 2160: 拉拉队排练 回文自动机
题目: Description 艾利斯顿商学院篮球队要参加一年一度的市篮球比赛了.拉拉队是篮球比赛的一个看点,好的拉拉队往往能帮助球队增加士气,赢得最终的比赛.所以作为拉拉队队长的楚雨荨同学知道,帮助 ...
- 【LeetCode】066. Plus One
题目: Given a non-negative integer represented as a non-empty array of digits, plus one to the integer ...
- Erlang generic standard behaviours -- gen_server terminate
gen_server 主体 module 已经分析完了(http://www.cnblogs.com/--00/p/4271982.html),接着,分析下gen_server 中的terminate ...
- 【转】 Pro Android学习笔记(四八):ActionBar(1):Home图标区
目录(?)[-] Home Icon 源代码 TextView的滚动 返回主activity或指定activity ActionBar在Android 3.0 SDK中为平板引入,在4.0中也 ...
- Ubuntu18.04安装Docker, centos7安装Docker
Ubuntu18.04安装Docker 第一种方法从Ubuntu的仓库直接下载安装: 安装比较简单,这种安装的Docker不是最新版本,不过对于学习够用了,依次执行下面命令进行安装. $ sudo a ...
- tomcat安装与运行
实验环境:CentOS7 使用系统yum仓库安装: #安装基本包和开发工具包 [root@~ localhost]#yum install -y java-1.8.0-openjdk java-1.8 ...
- js---倒计时的自动跳转.html
============================================================================== 倒计时的自动跳转.html <!DO ...
- MongoDB一些基本的命令
Win+R进入Dos命令窗口,输入cmd,进入MongoDB exe文件的所在目录,比如我的在E:\MongoDB\bin,分别执行:“E:”回车,然后:"cd mongodb/bin&qu ...
- 值得细细品读的URL资源
Web安全渗透方面的资源指南: 知乎综合问答:https://www.zhihu.com/question/21914899 渗透测试经典演练系统:http://www.freebuf.com/sec ...
- Hive 进阶
两种情况下不走map-reduce: 1. where ds >' ' //ds 是partition 2. select * from table //后面没有查询条件,什么都没有 1.建表 ...