Two Strings Swaps

本文探讨了一个字符串匹配问题,即通过最少的字符变换使两字符串可通过特定规则交换变为相同。介绍了问题背景、解决思路及实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题意:

You are given two strings aa and bb consisting of lowercase English letters, both of length nn. The characters of both strings have indices from 11 to nn, inclusive.

You are allowed to do the following changes:

  • Choose any index ii (1≤i≤n1≤i≤n) and swap characters aiaiand bibi;
  • Choose any index ii (1≤i≤n1≤i≤n) and swap characters aiaiand an−i+1an−i+1;
  • Choose any index ii (1≤i≤n1≤i≤n) and swap characters bibiand bn−i+1bn−i+1.

Note that if nn is odd, you are formally allowed to swap a⌈n2⌉a⌈n2⌉with a⌈n2⌉a⌈n2⌉ (and the same with the string bb) but this move is useless. Also you can swap two equal characters but this operation is useless as well.

You have to make these strings equal by applying any number of changes described above, in any order. But it is obvious that it may be impossible to make two strings equal by these swaps.

In one preprocess move you can replace a character in aa with another character. In other words, in a single preprocess move you can choose any index ii (1≤i≤n1≤i≤n), any character cc and set ai:=cai:=c.

Your task is to find the minimum number of preprocess moves to apply in such a way that after them you can make strings aa and bb equal by applying some number of changesdescribed in the list above.

Note that the number of changes you make after the preprocess moves does not matter. Also note that you cannot apply preprocess moves to the string bb or make any preprocess moves after the first change is made.

Input

The first line of the input contains one integer nn (1≤n≤1051≤n≤105) — the length of strings aa and bb.

The second line contains the string aa consisting of exactly nnlowercase English letters.

The third line contains the string bb consisting of exactly nnlowercase English letters.

Output

Print a single integer — the minimum number of preprocess moves to apply before changes, so that it is possible to make the string aa equal to string bb with a sequence of changes from the list above.

Examples

Input

7
abacaba
bacabaa

Output

4

Input

5
zcabd
dbacz

Output

0

Note

In the first example preprocess moves are as follows: a1:=a1:='b', a3:=a3:='c', a4:=a4:='a' and a5:=a5:='b'. Afterwards, a=a="bbcabba". Then we can obtain equal strings by the following sequence of changes: swap(a2,b2)swap(a2,b2) and swap(a2,a6)swap(a2,a6). There is no way to use fewer than 44preprocess moves before a sequence of changes to make string equal, so the answer in this example is 44.

In the second example no preprocess moves are required. We can use the following sequence of changes to make aa and bbequal: swap(b1,b5)swap(b1,b5), swap(a2,a4)swap(a2,a4).

 

题意:

输入相等长度的a,b字符串,问最少变换多少个字符可以使变换后的两个字符串

经过多次a[i]与b[i]、a[i]与a[n-i+1]、b[i]与b[n-i+1]j交换使a字符串与b字符串相等。

 

思路:

sum=0;

枚举i  让 l=i,r=len-i-1;

如果a[l]==b[l]&&a[r]==b[r]||a[l]==b[r]&&a[r]==b[l]||a[l]==a[r]&&b[l]==b[r]

continue;

如果a[l]==b[l]||a[r]==b[r]||a[l]==b[r]||a[r]==b[l]||b[l]==b[r]

sum++;

其他情况sum=sum+2;

最后判断len如果是奇数且a[len/2]!=b[len/2]

sum++;

输出sum;

 

代码:

#include<stdio.h>
int len;
char a[100861],b[100861];

int main()
{
    scanf("%d%s%s",&len,a,b);
    int sum=0;
    for(int i=0; i<len/2; i++)
    {
        int l=i,r=len-i-1;
        if(a[l]==b[l]&&a[r]==b[r]||a[l]==b[r]&&a[r]==b[l]||a[l]==a[r]&&b[l]==b[r])
            continue;
        else if(a[l]==b[l]||a[r]==b[r]||a[l]==b[r]||a[r]==b[l]||b[l]==b[r])
            sum++;
        else
            sum+=2;
    }
    if(len%2==1&&a[len/2]!=b[len/2])
        sum++;
    printf("%d\n",sum);
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值