fork(5) download
  1. procedure Swap (var a, b : string);
  2.  
  3. var
  4. t : string;
  5.  
  6. begin
  7. t := a;
  8. a := b;
  9. b := t;
  10. end;
  11.  
  12. function compare(const a, b: string): integer;
  13. var
  14. m, i, r: integer;
  15. s1, s2: string;
  16. begin
  17. m := length(a);
  18. s1 := a;
  19. if (length(b) > m) then begin
  20. //
  21. s1 := a + b;
  22. s2 := b;
  23. m := length(b);
  24. end
  25. else
  26. s2 := b + a;
  27. //
  28. r := 0;
  29. for i := 1 to m do begin
  30. //
  31. if (s1[i] < s2[i]) then r := -1
  32. else
  33. if (s1[i] > s2[i]) then r := 1;
  34. //
  35. if (0 <> r) then break;
  36. end;
  37. //
  38. compare := r;
  39. //
  40. writeln(a, ' ? ', b, ' = ', r);
  41. end;
  42.  
  43. var
  44. n, j, i : Integer;
  45. a : array [1..10] of string;
  46.  
  47. begin
  48. WriteLn;
  49. ReadLn (n);
  50.  
  51. for i := 1 to n do
  52. ReadLn (a[i]);
  53.  
  54. for i := 1 to n-1 do
  55. for j := 1 to n-i do
  56. if (compare(a[j], a[j+1]) < 0) then
  57. Swap (a[j], a[j+1]);
  58. i := 1;
  59. while (a[i] = '0') and (i < n) do
  60. Inc (i);
  61. for i := i to n do
  62. Write (a[i])
  63. end.
  64.  
Success #stdin #stdout 0.01s 4072KB
stdin
3
90
9
1
stdout
90 ? 9 = -1
90 ? 1 = 1
9 ? 90 = 1
9901