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

3 3 2
ABC
s 0 1
c 1 0

4 3 6
BCBA
s 0 1
c 1 0
s 0 2
s 1 2
c 2 1
c 0 0
stdout
Case #1: C
Case #2: AAB