fork download
  1. program wardrobe3;
  2. const MAX = 5000000;
  3. type elenco = array[1..MAX] of string[1];
  4. var m,k,i :qword;
  5. numero : qword;
  6. cifre : Ansistring;
  7. ccifre : array[1..MAX] of integer;
  8. potenzadieci : array [0..MAX] of qword;
  9. arrnum:array [1..MAX] of string[1];
  10.  
  11. procedure scambia (var x,y: string);
  12. var t:string;
  13. begin
  14. t:=x;
  15. x:=y;
  16. y:=t;
  17. end;
  18. Procedure ordinamento (estremoi,estremos: qword; var v : elenco; ordinato:boolean);
  19. var inf, sup, medio:qword;
  20. pivot :string[1];
  21. begin
  22. inf:=estremoi;
  23. sup:=estremos;
  24. medio:= (estremoi+estremos) div 2;
  25. pivot:=v[medio];
  26. repeat
  27. if (ordinato) then
  28. begin
  29. while (v[inf]<pivot) do inf:=inf+1;
  30. while (v[sup]>pivot) do sup:=sup-1;
  31. end;
  32. if inf<=sup then
  33. begin
  34. scambia(v[inf],v[sup]);
  35. inf:=inf+1;
  36. sup:=sup-1;
  37. end;
  38. until inf>sup;
  39. if (estremoi<sup) then ordinamento(estremoi,sup,v,ordinato);
  40. if (inf<estremos) then ordinamento(inf,estremos,v,ordinato);
  41. end;
  42. begin
  43. readln(m,k);
  44. readln(cifre);
  45. for i:=1 to m do arrnum[i]:=copy(cifre,i,1);
  46. for i:=1 to m do write(arrnum[i]);writeln;
  47. potenzadieci[0]:=1; numero:=0;
  48. for i:=1 to m do potenzadieci[i]:=(potenzadieci[i-1]*10);
  49. for i:=1 to m do begin numero:=numero + potenzadieci[m-i]*(ord(cifre[i]) - 48); end;
  50. writeln (numero);
  51. ordinamento (1,m,arrnum, true); writeln('ciao');
  52. for i:=1 to m do write (arrnum[i]); writeln;
  53.  
  54. end.
Success #stdin #stdout 0s 5320KB
stdin
6 10
782901
stdout
782901
782901
ciao
012789