Cpp Careless Tony

题目链接:http://cpp.zjut.edu.cn/ShowProblem.aspx?ShowID=1885

题面:

Careless Tony 
Time Limit:1000MS  Memory Limit:32768K

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.<BR> 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.<BR> Note: The text contents contain only the readable characters. The total length of each text is no longer than 80 characters.<BR>

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



题意:

     最少用多少时间修改后面那个串到前面那个串。


代码:

#include <iostream> 
#include <string>
using namespace std;
int main()
{
	int n,t;
	string s1,s2;
	bool flag;
	int p;
	cin>>n;
	while(n--)
	{
		cin>>t;
		cin>>s1>>s2;
		flag=true;
		p=0;
		for(int i=0;i<s1.length()&&i<s2.length();i++)
		{
			if(s1[i]!=s2[i])
			{
				flag=false;
				p=i;
				break;
			}
		}
		if(flag)
		{
			if(s1.length()>=s2.length())
			{
				cout<<t*(s1.length()-s2.length())<<endl;
			}
			else
			{
				cout<<(s2.length()-s1.length())*t<<endl;
			}
		}
		else
		{
			cout<<(s1.length()+s2.length()-2*p)*t<<endl;
		}
	} 
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值