[ZCMU OJ]1425: Careless Tony(小坑)

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

———————————————————————————————————————————

题意:给定测试组数、删除/增加一个字符串所需要的时间、正确字符串与错误字符串,输出修改该错误字符串的时间。要修改目标字符串必须从右到左删除直到目标字符串,再重新打印剩余部分的字母。

思路:首先建立两个数组存储正确与错误的输入,并利用pos标记错误的位置(pos初始化为错误数组的最后一个位置,因为要考虑没有写错的情况);再将两个数组平行比较找到错误字符出现的位置。最后用错误数组的长度减去pos的差乘以修改时间以及正确数组的长度减去pos的差乘以修改时间即可算出修改与输入的时间之和。

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int T;
	int t;
	char cor[100],mis[100];
	
	cin>>T;
	while(T--)
	{
		memset(cor,'/0',sizeof(cor));
		memset(mis,'/0',sizeof(mis)); //字符数组初始化 
		cin>>t;
		cin>>cor;
		cin>>mis;
		
		int pos=strlen(mis);//考虑没有写错的情况 
		
		for(int i=0;i<strlen(mis);i++)
		{
			if(cor[i]!=mis[i]&&mis[i]!='\0')
			{
				pos=i;//找到错误位置立即跳出 
				break; 
			}
		}
		int time=(strlen(mis)-pos)*t+(strlen(cor)-pos)*t;
		          //删除错误的      输入正确的(别忘了乘删除和输入所需时间) 
		cout<<time<<endl;
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值