UVA1588(Kickdown)。

时间:2023-03-09 20:19:16
UVA1588(Kickdown)。

只需要固定长串,拿着短串移动就好了。

我是从右往左移动,需要注意的是要判断两头重叠部分(左端重叠和右端重叠)的大小关系。

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring> using namespace std; int main()
{
char s1[];
char s2[];
char s3[];
int i,j;
while(scanf("%s",s1)!=EOF)
{
scanf("%s",s2);
int len1=strlen(s1);
int len2=strlen(s2);
for(i=len1; i<len1+len2; i++)
{
s1[i]='';
}
s1[i]='\0';
for(i=len2; i<len1+len2; i++)
s2[i]='';
s2[i]='\0';
if(len1<len2)
{
strcpy(s3,s1);
strcpy(s1,s2);
strcpy(s2,s3);
int x=len1;
len1=len2;
len2=x;
}
// puts(s1);
// puts(s2);
int t=;
int r=;
for(i=; i<=len1; i++)
{ for(j=len1-i; j<len1+len2-i; j++)
{
if((s1[j]-'')+(s2[j-len1+i]-'')>)
break;
}
if(j==len1+len2-i)
t=i; //printf("%d\n",t);
} for(i=; i<len2; i++)
{
for(j=; j<len2-i; j++)
{
if(s1[j]-''+s2[j+i]-''>)
break;
}
if(j==len2-i)
{r=i;
break;}
}
// printf("r=%d\n",r);
//int Max=max(r,t);
if(t==&&r==)
printf("%d\n",len1+len2);
else if(t==&&r!=)
printf("%d\n",len1+r);
else if(r==&&t!=)
{
if(t>len2)
t=len2;
printf("%d\n",len1+len2-t);
}
else
{
if(t>len2)
t=len2;
if(t>len2-r)
printf("%d\n",len1+len2-t);
else
printf("%d\n",len1+r);} }
return ;
}