刷题计划
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
.
.
.
.
.
.
分析
開(kāi)兩個(gè)數(shù)組a和w,a存正確的編號(hào),w存錯(cuò)誤的編號(hào)。
每輸入一個(gè)命令就判斷:
若為1,則:
看a數(shù)組里是否有該編號(hào),若沒(méi)有,就把該編號(hào)存進(jìn)a數(shù)組。其次,看w數(shù)組里是否有該編號(hào),有則刪去。
若為2,則:
看a數(shù)組里是否有該編號(hào),若沒(méi)有,就把該編號(hào)存進(jìn)w數(shù)組。注意:若w數(shù)組里已有該編號(hào),則要把該編號(hào)移至數(shù)組最后。
若為3,則:
把w數(shù)組倒著輸出,注意:如果編號(hào)的數(shù)量超過(guò)20個(gè),則只輸出w數(shù)組的最后20個(gè)。
.
.
.
.
.
.
程序:
var n,m,a1,w1,p,q,i,bz:longint; a,w:array[-30..200]of longint; procedure print; var i,j:longint; beginif w1<=20 thenbeginfor i:=w1 downto 1 dowrite(w[i],' ');writeln;end elsebeginfor i:=w1 downto w1-20+1 dowrite(w[i],' ');writeln;end; end;procedure work(u:longint); var i,t:longint; begint:=0;for i:=w1 downto 1 doif w[i]=u thenbegint:=i;break;end;if t<>0 thenbeginfor i:=t to w1-1 dow[i]:=w[i+1];w[w1]:=0;dec(w1);end;t:=0;for i:=1 to a1 doif a[i]=u thenbegint:=1;break;end;if t=0 thenbegininc(a1);a[a1]:=u;end;end;function finda(t:longint):boolean; var bz1,i:longint; beginbz1:=0;for i:=a1 downto 0 doif a[i]=t thenbeginbz1:=1;break;end;if bz1=0 then exit(false) else exit(true); end;procedure xc(t:longint); var bz1,i:longint; beginbz1:=0;for i:=1 to w1 doif w[i]=t thenbeginbz1:=i;break;end;if bz1=0 thenbegininc(w1);w[w1]:=t;end elsebeginfor i:=bz1 to w1-1 dow[i]:=w[i+1];w[w1]:=t;end; end;beginassign(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 dobeginread(p);if p=1 thenbeginreadln(q);work(q);end elseif p=2 thenbeginreadln(q);if finda(q)=false then xc(q);end elseif p=3 then print;end;close(input);close(output); end.轉(zhuǎn)載于:https://www.cnblogs.com/YYC-0304/p/9499998.html
總結(jié)