刷题计划
Description
Input
Output
Sample Input
10000 12
2 1
3
2 9999
3
1 1
3
2 1
3
2 10000
3
2 9999
3
Sample Output
1
9999 1
9999
9999
10000 9999
9999 10000
Data Constraint
.
.
.
.
.
.
分析
开两个数组a和w,a存正确的编号,w存错误的编号。
每输入一个命令就判断:
若为1,则:
看a数组里是否有该编号,若没有,就把该编号存进a数组。其次,看w数组里是否有该编号,有则删去。
若为2,则:
看a数组里是否有该编号,若没有,就把该编号存进w数组。注意:若w数组里已有该编号,则要把该编号移至数组最后。
若为3,则:
把w数组倒着输出,注意:如果编号的数量超过20个,则只输出w数组的最后20个。
.
.
.
.
.
.
程序:
var
n,m,a1,w1,p,q,i,bz:longint;
a,w:array[-30..200]of longint;
procedure print;
var
i,j:longint;
begin
if w1<=20 then
begin
for i:=w1 downto 1 do
write(w[i],' ');
writeln;
end else
begin
for i:=w1 downto w1-20+1 do
write(w[i],' ');
writeln;
end;
end;
procedure work(u:longint);
var
i,t:longint;
begin
t:=0;
for i:=w1 downto 1 do
if w[i]=u then
begin
t:=i;
break;
end;
if t<>0 then
begin
for i:=t to w1-1 do
w[i]:=w[i+1];
w[w1]:=0;
dec(w1);
end;
t:=0;
for i:=1 to a1 do
if a[i]=u then
begin
t:=1;
break;
end;
if t=0 then
begin
inc(a1);
a[a1]:=u;
end;
end;
function finda(t:longint):boolean;
var
bz1,i:longint;
begin
bz1:=0;
for i:=a1 downto 0 do
if a[i]=t then
begin
bz1:=1;
break;
end;
if bz1=0 then exit(false) else exit(true);
end;
procedure xc(t:longint);
var
bz1,i:longint;
begin
bz1:=0;
for i:=1 to w1 do
if w[i]=t then
begin
bz1:=i;
break;
end;
if bz1=0 then
begin
inc(w1);
w[w1]:=t;
end else
begin
for i:=bz1 to w1-1 do
w[i]:=w[i+1];
w[w1]:=t;
end;
end;
begin
assign(input,'problem.in');
reset(input);
assign(output,'problem.out');
rewrite(output);
readln(n,m);
a1:=0;w1:=0;
fillchar(a,sizeof(a),0);
fillchar(w,sizeof(w),0);
for i:=1 to m do
begin
read(p);
if p=1 then
begin
readln(q);
work(q);
end else
if p=2 then
begin
readln(q);
if finda(q)=false then xc(q);
end else
if p=3 then print;
end;
close(input);
close(output);
end.