内容目录
直接用数组记录出现次数,每遇到一对,就扔入解中。
Program Cards; const maxn=300000; var n,i,p,size:longint; a:array[1..5000] of longint; q1,q2:array[1..maxn] of longint; begin assign(input,'input.txt'); assign(output,'output.txt'); reset(input); rewrite(output); read(n); fillchar(a,sizeof(a),0); size:=1; for i:=1 to 2*n do begin read(p); if a[p]>0 then begin q1[size]:=a[p];q2[size]:=i; inc(size); a[p]:=0; end else a[p]:=i; end; if size<>n+1 then writeln('-1') else for i:=1 to n do writeln(q1[i],' ',q2[i]); close(input); close(output); end.