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.
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.
For each test case, print in one line the minimal time taken for Tony to correct his mistake.
#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;
}