1425: Careless Tony(思维)

1425: Careless Tony
Time Limit: 1 Sec Memory Limit: 128 MB
[Submit][Status][Web Board]
Description

Tony is such a careless typist that he finds himself making mistakes AGAIN. What’s worse, the cursor key is not working so that he can only use the backspace key to reach the place where the mistake is, and then type whatever he’s deleted on the way AGAIN ?

Now let’s help Tony find out at least how long it will cost him to correct his mistake.

Input

The first line of input contains an integer N, which is the number of test cases. Then N test cases follow.

Each test case consists of 3 lines of input:

the 1st line contains a positive integer t (<= 100), which is the time taken for Tony to delete/input a character;

the 2nd line contains the correct content of text;

and the 3rd line contains the text typed by Tony.

Note: The text contents contain only the readable characters. The total length of each text is no longer than 80 characters.

Output

For each test case, print in one line the minimal time taken for Tony to correct his mistake.

Sample Input

2
1
WishingBone
WashingBone
1
Oops
Oooops

Sample Output

20
6

HINT

Source

ACcode~:

#include <stdio.h>
#include <string.h>
char a[100],b[100];
int main()
{
    int n,t,pos,Lr,Lt,sum;
    scanf("%d",&n);
    while(n--)
    {
        memset(a,'\0',sizeof(a));
        memset(b,'\0',sizeof(b));
        pos = -1;
        scanf("%d",&t);
        scanf("%s",a);
        scanf("%s",b);
        Lr = strlen(a);
        Lt = strlen(b);
        for(int i = 0; i < Lr; i++)
        {
            if(a[i] != b[i])
            {
                pos = i;
                break;
            }
        }
        if(pos != -1)
            sum = (Lt+Lr-2*pos)*t;
        else
             sum = (Lt - Lr)*t;//在正确字符串长度内未出现失配
        printf("%d\n",sum);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Leo Bliss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值