码迷,mamicode.com
首页 > 其他好文 > 详细

Cpp Careless Tony

时间:2015-04-18 08:45:36      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:最水题   思维   入门   字符串   

题目链接: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;
}


Cpp Careless Tony

标签:最水题   思维   入门   字符串   

原文地址:http://blog.csdn.net/david_jett/article/details/45104103

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!