- 小胖的水果
- 2013-05-10 19:41:42 @
var s,a,b:string;
i,j,k,ans,min,p:longint;
begin
while not(eof) do begin
readln(s);
p:=pos(' ',s);
a:=copy(s,1,p-1);
b:=copy(s,p+1,length(s));
i:=1;
j:=1;
ans:=0;
while i<=length(a)do begin
k:=j;
while j<=length(b) do begin
if a[i]=b[j] then begin
inc(ans);
break;
end;
inc(j);
end;
if j=length(b)+1 then j:=k;
inc(i);
end;
min:=length(s)-1-ans;
i:=1;
j:=1;
ans:=0;
while i<=length(b)do begin
k:=j;
while j<=length(a) do begin
if b[i]=a[j] then begin
inc(ans);
break;
end;
inc(j);
end;
if j=length(a)+1 then j:=k;
inc(i);
end;
if length(s)-1-ans<min then min:=length(s)-1-ans;
writeln(min);
end;
end.
2 条评论
-
TenderRun LV 10 @ 2015-07-29 17:31:02
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
char s[2][110];
int main()
{
int ans=0;
while(scanf("%s%s",s[0],s[1])==2)
{
int maxn=-1000;
ans=0;
int now=0;
int s1=strlen(s[0])-1;
int s2=strlen(s[1])-1;
for(int i=0;i<=s1;i++)
{
for(int j=0;j<=s2;j++)
{ ans=0;
if(s[0][i]==s[1][j])
{ans++;
for(int k=1;k<=s1&&k<=s2;k++)
{
if(s[0][(i+k)%(s1+1)]!=s[1][(j+k)%(s2+1)])
break;
ans++;
}
}
if(ans>maxn)maxn=ans;
}
}printf("%d\n",s1+s2+2-maxn);
}
} -
2013-05-10 20:04:37@
orz请参考*编辑器快速入门*以进行代码块化。
- 1