当前位置: 首页 > 工具软件 > TonY > 使用案例 >

ZCMU--1425: Careless Tony(C语言)

田英卓
2023-12-01

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
解析:我们肯定删除到第一个不同的位置,然后再重新打字,因此我们找到第一个不同的位置,然后计算我们需要删除几个字符,需要重新打入几个字符,最后乘上单个操作的时间即可。
#include <stdio.h>
#include <string.h>
char a[85],b[85];
int main()
{
	int n,t,len1,i,m,len2;	
	scanf("%d",&n);
	while(n--){
		scanf("%d",&l);
		scanf("%s%s",a,b);
		len1=strlen(a),len2=strlen(b);
		m=0;	//初始化需要校对的a[]的位置 
		for(i=0;i<len2;i++){
			if(b[i]==a[m]){
				m++;	//相同,那么下一个 
			}else{
				break;	//找到第一个不同的位置,直接退出 
			}
		}
		t=(len2-i)*l+(len1-i)*l;//前者是删除所需时间,后者是需要重新打入字符的时间 
		printf("%d\n",t);
	}
	return 0;
}

 类似资料: