- 笨笨的单词排序
- 2009-01-29 01:46:39 @
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案错误...程序输出比正确答案长
├ 测试数据 03:运行超时...
├ 测试数据 04:运行超时...
├ 测试数据 05:运行超时...
├ 测试数据 06:答案正确... 166ms
├ 测试数据 07:答案正确... 338ms
├ 测试数据 08:答案正确... 0ms
├ 测试数据 09:答案错误...程序输出比正确答案长
├ 测试数据 10:运行超时...
---|---|---|---|---|---|---|---|-
Unaccepted 有效得分:40 有效耗时:504ms
program p1500;
type arr=array[1..26]of string; str=string;
function p(z:str;x:str;w:arr):integer;
var f,g:string; h,o:integer; //z,x:str; w:arr;
begin
f:=copy(z,1,1);
g:=copy(x,1,1);
h:=0; o:=0;
while (h1) and (h2) and (h3) do
begin
o:=o+1;
if w[o]=f then h:=h+1;
if w[o]=g then h:=h+2;
end;
if h=1 then p:=1;
if h=2 then p:=2;
if h=3 then begin
f:=copy(z,2,length(z)-1);
g:=copy(x,2,length(x)-1);
p:=p(f,g,w);
end;
end;
var
a,v:string;
b:array[1..1000]of string;
c:array[1..26]of string;
k,l,n,m:integer;
begin
readln(a);
for k:=1 to 26 do c[k]:=copy(a,k,1);
readln(n);
for k:=1 to n do readln(b[k]);
read(m);
if m=1 then
for k:=1 to n-1 do
for l:=1 to n-1 do
if p(b[l],b[l+1],c)=2 then begin
v:=b[l];
b[l]:=b[l+1];
b[l+1]:=v;
end;
if m=0 then
for k:=1 to n-1 do
for l:=1 to n-1 do
if p(b[l],b[l+1],c)=1 then begin
v:=b[l];
b[l]:=b[l+1];
b[l+1]:=v;
end;
for k:=1 to n do
writeln(b[k]);
end.
我用的冒泡