ZCMU-1425-Careless Tony

1425: Careless Tony

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 92   Solved: 29
[ 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

【解析】
这道题确实纠结了好久因为实在是看不懂啊..最后终于懂了。第一行输入的是有几组数据,第二行输入的是操作一个字符需要的时间,第三行输入的是正确的字符串,第四行是你输入的字符串。然后就行比对,看两者之间有哪些是不一样的。找到第一个不相同的字符,然后我们从第二个字符串的最后开始就行删除。删到第一个不一样的位置为止,如果两者之间长度相同并且字符都一样的话我们就输出0.如果第二个字符串的长度大于第一个字符串的长度,并且和第一个字符串长度相同的部分都是相同的那我们只需要删除后半部分就可以了,否则的话删除到第一个位置不一样的地方然后再变回和第一个字符串一样长度的字符串。
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n,t;
	string s1,s2;
	int flag;
	int p;
	cin>>n;
	while(n--)
	{
		cin>>t;
		cin>>s1>>s2;
		flag=1;
		p=0;
		for(int i=0;i<s1.size()&&i<s2.size();i++)
		{
			if(s1[i]!=s2[i])//寻找第一个不相同的字符串
			{
				flag=0;//判断字符是否相同
				p=i;
				break;
			}
		}
		if(flag)//字符都相同的话
		{
			if(s1.size()>=s2.size())
			{
				cout<<t*(s1.size()-s2.size())<<endl;//第一个字符串的长度减去第二个字符串的长度表示还有多少个字符
			}
			else
			{
				cout<<(s2.size()-s1.size())*t<<endl;//还需要删除多少个字符
			}
		}
		else
		{
			cout<<(s1.size()+s2.size()-2*p)*t<<endl;//表示的是我们先删除,然后再变成和第一个字符串一样的字符串
		}
	}
	return 0;
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值