Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of
equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of
the same length, which is defined as the number of positions in which S and T have
different characters. For example, the Hamming distance between words "permanent" and "pergament"
is two, as these words differ in the fourth and sixth letters.

Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common
mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S,
so that the Hamming distance between a new string S and string T would
be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.

Help him do this!

Input

The first line contains integer n (1 ≤ n ≤ 200 000)
— the length of strings S and T.

The second line contains string S.

The third line contains string T.

Each of the lines only contains lowercase Latin letters.

Output

In the first line, print number x — the minimum possible Hamming distance between strings S and T if
you swap at most one pair of letters in S.

In the second line, either print the indexes i and j (1 ≤ i, j ≤ ni ≠ j),
if reaching the minimum possible distance is possible by swapping letters on positions i and j,
or print "-1 -1", if it is not necessary to swap characters.

If there are multiple possible answers, print any of them.

Sample test(s)
input
9
pergament
permanent
output
1
4 6
input
6
wookie
cookie
output
1
-1 -1
input
4
petr
egor
output
2
1 2
input
6
double
bundle
output
2
4 1
Note

In the second test it is acceptable to print i = 2, j = 3.

看了别人的代码,发现两个字符串的数字匹配只有26*26*2种情况,所以读入所有情况就行了,这里有一点要注意,就是a[i][j]等于i,这样待会要输出交换位置时就可以直接输出了。

#include<stdio.h>
#include<string.h>
char str1[200005],str2[200005];
int a[40][40];
int main()
{
int n,i,t,flag,x,y,k,j;
while(scanf("%d",&n)!=EOF)
{
memset(a,0,sizeof(a));
memset(str1,0,sizeof(str1));
memset(str2,0,sizeof(str1));
scanf("%s%s",str1+1,str2+1);
t=flag=x=y=0;
for(i=1;i<=n;i++)
{
if(str1[i]!=str2[i])
{
a[str1[i]-'a'+1][str2[i]-'a'+1]=i;
t++;
}
} for(i=1;i<=26;i++)
{
for(j=1;j<=26;j++)
{
if(a[i][j] && a[j][i])
{
flag=1;
x=a[i][j];
y=a[j][i];
break;
}
}
if(flag==1)
break;
}
if(flag==1)
{
printf("%d\n",t-2);
printf("%d %d\n",x,y);
continue;
} for(i=1;i<=26;i++)
{
for(j=1;j<=26;j++)
{
if(a[i][j])
{
for(k=1;k<=26;k++)
{
if(a[j][k])
{
flag=1;
x=a[i][j];
y=a[j][k];
break;
}
}
}
if(flag==1)
break;
}
if(flag==1)
break;
}
if(flag==1)
{
printf("%d\n",t-1);
printf("%d %d\n",x,y);
continue;
} printf("%d\n",t);
printf("-1 -1\n");
}
return 0;
}

Codeforces Round #296 (Div. 2B. Error Correct System的更多相关文章

  1. Codeforces Round #296 (Div. 1) C. Data Center Drama 欧拉回路

    Codeforces Round #296 (Div. 1)C. Data Center Drama Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xx ...

  2. Codeforces Round #296 (Div. 2) B. Error Correct System

    B. Error Correct System time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  3. CodeForces Round #296 Div.2

    A. Playing with Paper 如果a是b的整数倍,那么将得到a/b个正方形,否则的话还会另外得到一个(b, a%b)的长方形. 时间复杂度和欧几里得算法一样. #include < ...

  4. 字符串处理 Codeforces Round #296 (Div. 2) B. Error Correct System

    题目传送门 /* 无算法 三种可能:1.交换一对后正好都相同,此时-2 2.上面的情况不可能,交换一对后只有一个相同,此时-1 3.以上都不符合,则不交换,-1 -1 */ #include < ...

  5. Codeforces Round #313 (Div. 2) A. Currency System in Geraldion

    A. Currency System in Geraldion Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/co ...

  6. Codeforces Round #313 (Div. 2) A. Currency System in Geraldion 水题

    A. Currency System in Geraldion Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/c ...

  7. Codeforces Round #296 (Div. 1) E. Triangles 3000

    http://codeforces.com/contest/528/problem/E 先来吐槽一下,一直没机会进div 1, 马力不如当年, 这场题目都不是非常难,div 2 四道题都是水题! 题目 ...

  8. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 栈 链表

    E. Correct Bracket Sequence Editor 题目连接: http://www.codeforces.com/contest/670/problem/E Description ...

  9. 【打CF,学算法——一星级】Codeforces Round #313 (Div. 2) A. Currency System in Geraldion

    [CF简单介绍] 提交链接:http://codeforces.com/contest/560/problem/A 题面: A. Currency System in Geraldion time l ...

随机推荐

  1. Dubbo 配置的加载流程

    配置加载流程 在SpringBoot应用启动阶段,Dubbo的读取配置遵循以下原则 Dubbo支持了多层级的配置,按照预先定义的优先级自动实现配置之间的覆盖,最终所有的配置汇总到数据总线URL后,驱动 ...

  2. AgileConfig - RESTful API 介绍

    AgileConfig AgileConfig是一个基于.net core开发的轻量级配置中心. AgileConfig秉承轻量化的特点,部署简单.配置简单.使用简单.学习简单,它只提取了必要的一些功 ...

  3. 二进制部署kubernetes

    Kubernetes二进制安装 环境准备: 主机环境:做好主机名hosts文件映射 硬件2cpu  2G内存 192.168.30.21 k8s-master 192.168.30.22 k8s-no ...

  4. ABAP 面试问题和答案

    What is an ABAP data dictionary?- ABAP 4 data dictionary describes the logical structures of the obj ...

  5. Python设计模式面向对象编程

    前言   本篇文章是基于极客时间王争的<设计模式之美>做的总结和自己的理解.  说到面向对象编程,作为一个合格的Pythoner,可以说信手拈来.毕竟在Python里"万物都是对 ...

  6. 解决安装mysql动态库libstdc++.so.6、libc.so.6版本过低问题

    初始化mysql报错: ./bin/mysqld: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by ...

  7. 彻底解决小程序无法触发SESSION问题

    一.首先找到第一次发起网络请求的地址,将服务器返回set-cookie当全局变量存储起来 wx.request({ ...... success: function(res) { console.lo ...

  8. /bin/sh: cc: command not found

    make的时候报错:/bin/sh: cc: command not found 解决: 1. sudo yum -y install gcc gcc-c++ libstdc++-devel 2. m ...

  9. Vue中组件间通信的方式

    Vue中组件间通信的方式 Vue中组件间通信包括父子组件.兄弟组件.隔代组件之间通信. props $emit 这种组件通信的方式是我们运用的非常多的一种,props以单向数据流的形式可以很好的完成父 ...

  10. CI/CD 最佳实践的基本原则 互联网后端架构 2020-10-04

    https://mp.weixin.qq.com/s/UfGmCueEm8n2jdegng1F_g CI/CD 最佳实践的基本原则 互联网后端架构 2020-10-04