记录编号 878 评测结果 AAAAAA
题目名称 队列基本操作 最终得分 60
用户昵称 Gravatar书剑飘零 是否通过 通过
代码语言 Pascal 运行时间 10.000 s
提交时间 2008-07-22 20:24:43 内存使用 0.00 MiB
显示代码纯文本
program cch(input,output,f1,f2);   
var  
 f1,f2:text;   
 head,tail,q,i,n:integer;   
 x:longint;   
 a:array[1..100] of longint;   
procedure empty;   
begin  
 head:=0; tail:=0;   
end;   
  
procedure inqueue(x:longint);   
begin  
 if tail-head+1=10 then writeln(f2,'queue out')   
    else begin  
     if head=0 then head:=1;   
     inc(tail);   
     a[tail]:=x;   
    end;   
end;   
procedure outqueue;   
begin  
  
 if (head=0)or(head>tail) then writeln(f2,'queue empty')   
           else inc(head);   
end;   
procedure print;   
var  
 i:integer;   
begin  
 if head=0 then exit;   
 writeln(f2,tail-head+1);   
 for i:=head to tail-1 do write(f2,a[i],' ');   
 writeln(f2,a[tail]);   
end;   
  
begin  
 assign(f1,'queue.in');   
 assign(f2,'queue.out');   
 reset(f1);   
 rewrite(f2);   
 readln(f1,n);   
 for i:=1 to n do begin  
  read(f1,q);   
  case q of  
  1:empty;   
  2:begin readln(f1,x);   
         inqueue(x);   
    end;   
  3:outqueue;   
  4:print;   
  end;   
 end;   
 close(f1);   
 close(f2);   
end.  
program cch(input,output,f1,f2);
var
 f1,f2:text;
 head,tail,q,i,n:integer;
 x:longint;
 a:array[1..100] of longint;
procedure empty;
begin
 head:=0; tail:=0;
end;

procedure inqueue(x:longint);
begin
 if tail-head+1=10 then writeln(f2,'queue out')
    else begin
     if head=0 then head:=1;
     inc(tail);
     a[tail]:=x;
    end;
end;
procedure outqueue;
begin

 if (head=0)or(head>tail) then writeln(f2,'queue empty')
           else inc(head);
end;
procedure print;
var
 i:integer;
begin
 if head=0 then exit;
 writeln(f2,tail-head+1);
 for i:=head to tail-1 do write(f2,a[i],' ');
 writeln(f2,a[tail]);
end;

begin
 assign(f1,'queue.in');
 assign(f2,'queue.out');
 reset(f1);
 rewrite(f2);
 readln(f1,n);
 for i:=1 to n do begin
  read(f1,q);
  case q of
  1:empty;
  2:begin readln(f1,x);
         inqueue(x);
    end;
  3:outqueue;
  4:print;
  end;
 end;
 close(f1);
 close(f2);
end.