fork download
  1. Program cestini;
  2.  
  3. const
  4. MAXQ = 300000;
  5. MAXN = 500000;
  6.  
  7. var
  8. M, N, Q, T, i,a, b, test : LongInt;
  9. S, ans : AnsiString;
  10. qtype : char;
  11. v : Array[0..MAXN-1] of Ansistring;
  12.  
  13. begin
  14. {
  15.   decommenta le due righe seguenti se vuoi leggere/scrivere da file
  16.   assign(input, 'input.txt'); reset(input);
  17.   assign(output, 'output.txt'); rewrite(output);
  18. }
  19.  
  20. ReadLn(T);
  21. for test:=1 to T do begin
  22. ReadLn();
  23. ReadLn(N, M, Q);
  24. for i:=0 to Q-1 do begin v[i]:='';Setlength(v[i],0); end;
  25. ReadLn(S);
  26. ans := '';
  27. v[0]:=S;
  28. Setlength(v[0],length(S));
  29. for i:=0 to Q-1 do
  30. begin
  31. ReadLn(qtype, a, b);
  32. if qtype='s' then
  33. begin
  34. v[b]:=v[b]+v[a][length(v[a])];
  35. delete(v[a],length(v[a]),1);
  36. SetLength(v[a],length(v[a]));
  37. SetLength(v[b],length(v[b]));
  38. end
  39. else
  40. if qtype='c' then ans:=ans+v[a][b+1];
  41. end;
  42.  
  43. Write('Case #', test, ': ');
  44. WriteLn(ans);
  45. end;
  46.  
  47. end.
  48.  
  49.  
Success #stdin #stdout 0.01s 5316KB
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