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. 借助window.performance实现基本的前端基础性能监控日志

    借助window.performance实现基本的前端基础性能监控日志并二次重写console方法方便日常前端console日志的调试 npm install sn-console

  2. LeetCode876 链表的中间结点

    给定一个带有头结点 head 的非空单链表,返回链表的中间结点. 如果有两个中间结点,则返回第二个中间结点. 示例 1: 输入:[1,2,3,4,5] 输出:此列表中的结点 3 (序列化形式:[3,4 ...

  3. 剑指offer-56数组中数字出现的次数

    题目 一个整型数组 nums 里除两个数字之外,其他数字都出现了两次.请写程序找出这两个只出现一次的数字.要求时间复杂度是O(n),空间复杂度是O(1). 输入:nums = [4,1,4,6] 输出 ...

  4. [工作札记]02: .Net Winform控件TreeView最简递归绑定方法

    前言:Treeview控件是我们在WinForm.WebForm开发中经常使用的控件,需要从数据库动态加载数据,然后递归绑定每一个节点:同样,递归的思路在其他程序中也经常运用,包括.Net MVC等. ...

  5. 爬虫-urllib3模块的使用

    urllib3是一个功能强大,对SAP健全的 HTTP客户端,许多Python生态系统已经使用了urllib3. 一.安装 sudo pips install urllib3 二.创建PoolMana ...

  6. 如何实现CentOS服务器的扩容??

    Linux的硬盘识别: 一般使用"fdisk -l"命令可以列出系统中当前连接的硬盘 设备和分区信息.新硬盘没有分区信息,则只显示硬盘大小信息. 1.关闭服务器加上新硬盘 2.启动 ...

  7. 十七:SQL注入之二次加解密,DNS注入

    加解密,二次,DNSlog注入 注入原理,演示案例,实际应用. less-21关,base64进行解密 encode加密decode解密 cookie处注入 判断加密算法,然后进行注入 less-24 ...

  8. python面向对象基础-属性/方法

  9. 关于QTableWidget中单元格拖拽实现

    无重写函数实现单元格拖拽 缺点:需要额外设置一个记录拖拽起始行的私有成员变量和拖拽列的初始QList数据成员. 优点:无需重构函数,对于QT中信号和槽的灵活运用 信号和槽 // signal void ...

  10. LeetCode653. 两数之和 IV - 输入 BST

    题目 直接暴力 1 class Solution { 2 public: 3 vector<int>ans; 4 bool findTarget(TreeNode* root, int k ...