fork download
  1. program cestini;
  2.  
  3. const
  4. MAX = 100000;
  5.  
  6. var
  7. M, N, Q, i, h : LongInt;
  8. t: char;
  9. a, b , index : Array[0..MAX-1] of LongInt;
  10. v: array of array of longint;
  11.  
  12.  
  13. procedure inizia (N:Longint; M:Longint) ;
  14. var j:longint;
  15. begin
  16. setLength(V, M,0);
  17. setLength(V[0], N);
  18. for j:=0 to N-1 do V[0][j]:= j;
  19. index[0]:=N;
  20. for j:=1 to M-1 do index[j]:= 0;
  21. end;
  22. Procedure sposta (a:Longint;b:Longint);
  23. begin
  24. setLength(V[b], index[b]+1);
  25. V[b][index[b]]:=V[a][index[a]-1];
  26. index[a]:=index[a]-1;
  27. index[b]:=index[b]+1;
  28.  
  29. end;
  30.  
  31. function controlla (a:Longint;i:Longint) : longint;
  32.  
  33. begin
  34. if index[a]+1<=i then controlla:=-1
  35. else controlla:=V[a][i];
  36. writeln(controlla) ;
  37.  
  38. end;
  39.  
  40.  
  41. begin
  42. {
  43.   decommenta le due righe seguenti se vuoi leggere/scrivere da file
  44.   assign(input, 'input.txt'); reset(input);
  45.   assign(output, 'output.txt'); rewrite(output);
  46. }
  47.  
  48. ReadLn(N, M, Q);
  49. inizia(N,M);
  50. for i:=0 to Q-1 do
  51. begin
  52. readln(t,a[i],b[i]);
  53. if t='s' then sposta(a[i],b[i])
  54. else if t='c' then controlla(a[i],b[i]);
  55. end;
  56. end.
  57.  
Success #stdin #stdout 0s 5324KB
stdin
3 3 2
s 0 1
c 1 0
s 1 0
c 1 0
stdout
2