#include <stdio.h>
#include <string.h>
int main()
{
int len1,len2,i,j,L,K,k;
char st1[105],st2[105],st3[105];
while(gets(st1))
{
gets(st2);
len1=strlen(st1);
len2=strlen(st2);
if(len1>len2)
{
int t=len1;
len1=len2;
len2=t;
strcpy(st3,st1);
strcpy(st1,st2);
strcpy(st2,st3);
}
for(i=0;i<len2;i++)
{
L=len1;
K=L+i;
if(K>len2) L=len1+len2-K;
for(j=0;j<L;j++)
{
if(st1[j]=='2'&&st2[i+j]=='2') break;
}
for(k=0;k<L;k++)
{
if(st1[len1-k-1]=='2'&&st2[len2-i-k-1]=='2') break;
}
if(j==L||k==L)
{
printf("%d\n",len2+len1-L);
break;
}
}
if(i==len2) printf("%d\n",len2+len1);
}
return 0;
#include <string.h>
int main()
{
int len1,len2,i,j,L,K,k;
char st1[105],st2[105],st3[105];
while(gets(st1))
{
gets(st2);
len1=strlen(st1);
len2=strlen(st2);
if(len1>len2)
{
int t=len1;
len1=len2;
len2=t;
strcpy(st3,st1);
strcpy(st1,st2);
strcpy(st2,st3);
}
for(i=0;i<len2;i++)
{
L=len1;
K=L+i;
if(K>len2) L=len1+len2-K;
for(j=0;j<L;j++)
{
if(st1[j]=='2'&&st2[i+j]=='2') break;
}
for(k=0;k<L;k++)
{
if(st1[len1-k-1]=='2'&&st2[len2-i-k-1]=='2') break;
}
if(j==L||k==L)
{
printf("%d\n",len2+len1-L);
break;
}
}
if(i==len2) printf("%d\n",len2+len1);
}
return 0;
}
心得:WA了2次,应该双向判断,还有len作为下标应该减一。最后,中国男篮今晚总决赛打菲律宾,加油!!!