var i,j,k,l,n,m,ans:longint;
a,b:ansistring;
p:boolean;
begin
readln(a);
readln(b);
l:=1; ans:=0; n:=length(a); m:=length(b);
while l<=m-n+1 do
begin
while (a[1]<>b[l]) do
begin
inc(l);
if l>m-n+1 then
begin
write(ans);
halt;
end;
end;
p:=true;
for i:=2 to n do
if a[i]<>b[l+i-1] then
begin
p:=false;
break;
end;
if p then
begin
m:=m-n;
inc(ans);
delete(b,l,n);
if l>n then l:=l-n
else l:=1;
end
else inc(l);
end;
write(ans);
end.
状态: Unaccepted
测评机: Xeost[5]
得分: 90分
提交日期: 2011-5-27 14:17:00
有效耗时: 2063毫秒
测试结果1: 通过本测试点|有效耗时156ms
测试结果2: 通过本测试点|有效耗时219ms
测试结果3: 通过本测试点|有效耗时172ms
测试结果4: 通过本测试点|有效耗时187ms
测试结果5: 通过本测试点|有效耗时375ms
测试结果6: 通过本测试点|有效耗时360ms
测试结果7: 通过本测试点|有效耗时375ms
测试结果8: 测试结果错误.错误结果为:1846
正确结果应为:1600
测试结果9: 通过本测试点|有效耗时172ms
测试结果10: 通过本测试点|有效耗时47ms
AC代码:
var i,j,k,l,n,m,ans:longint;
a,b:ansistring;
p:boolean;
begin
readln(a);
readln(b);
l:=1; ans:=0; n:=length(a); m:=length(b);
while l<=m-n+1 do
begin
while (a[1]<>b[l]) do
begin
inc(l);
if l>m-n+1 then
begin
write(ans);
halt;
end;
end;
p:=true;
for i:=1 to n do
if a[i]<>b[l+i-1] then
begin
p:=false;
break;
end;
if p then
begin
m:=m-n;
inc(ans);
delete(b,l,n);
if l>m then l:=m;
for j:=1 to n do
if (l>1)and(a[1]<>b[l]) then dec(l)
else break;
if l=0 then break;
end
else inc(l);
end;
write(ans);
end.
//以这种方法只会找到第一个与a[1]相同的字符,然后重新计算,
//如果a串中还有与a[1] 相同的字符,就会少删除几次,如:
//aabb
//aaaaaaaabbbbbbbb
//正确结果应为:4 而本程序只能得出:1,
//所以我认为第8组数据错在这里:
//if l>m then l:=m;
//for j:=1 to n do
//if (l>1)and(a[1]<>b[l]) then dec(l)
//else break;
//if l=0 then break;
状态: Accepted
测评机: Xeond[6]
得分: 100分
提交日期: 2011-5-27 17:36:00
有效耗时: 2703毫秒
测试结果1: 通过本测试点|有效耗时172ms
测试结果2: 通过本测试点|有效耗时375ms
测试结果3: 通过本测试点|有效耗时188ms
测试结果4: 通过本测试点|有效耗时203ms
测试结果5: 通过本测试点|有效耗时406ms
测试结果6: 通过本测试点|有效耗时359ms
测试结果7: 通过本测试点|有效耗时407ms
测试结果8: 通过本测试点|有效耗时359ms
测试结果9: 通过本测试点|有效耗时187ms
测试结果10: 通过本测试点|有效耗时47ms