无语了,看了别人的代码之后,感觉自己可傻。如果自己在认真想想,会不会想出来呢?
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int c,t;
int i,j=0,flag=0,x;
char correct[100],tony[100];
int ncases,time;
scanf("%d",&ncases);
while(ncases--)
{
flag=0;
scanf("%d",&time);
getchar();
gets(correct);
gets(tony);
c=strlen(correct);
t=strlen(tony);
for(i=0,j=0;i<c&&j<t;i++,j++)
{
if(correct[i]==tony[j])
continue;
else
{
flag=1;
break;
}
}
if(flag==0)
{
x=c-t;
x=abs(x);
printf("%d",x*time);
}
else
{
printf("%d",(t-j+c-i)*time);
}
if(ncases)
printf("\n");
}
return 0;
}