SlepoiKrot

Untitled

Feb 26th, 2018
89
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program NumberA;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6. SysUtils;
  7. var
  8. n, i, m, j, min, ch: integer;
  9. a: array [1..100] of integer;
  10. begin
  11. readln (n, m);
  12. ch := 0;
  13. for i := 1 to m do
  14. read (a[i]);
  15. min := a[1];
  16. j := 1;
  17. ch := 0;
  18. for i := 2 to m do begin
  19. if (a[i] = min + j) then
  20. inc (j)
  21. else if (j >= 2) then begin
  22. inc (ch);
  23. if (ch = 1) then
  24. write (min,'-',a[i-1])
  25. else
  26. write (',',min,'-',a[i-1]);
  27. min := a[i];
  28. j := 1;
  29. end
  30. else begin
  31. inc (ch);
  32. if (ch = 1) then
  33. write (a[i-1])
  34. else
  35. write (',', a[i-1]);
  36. min := a[i];
  37. j := 1;
  38. end;
  39. end;
  40. if (j < 2) then begin
  41. inc (ch);
  42. if (ch = 1) then
  43. write (a[m])
  44. else
  45. write (',',a[m]);
  46. end
  47. else begin
  48. inc (ch);
  49. if (ch = 1) then
  50. write (min,'-',a[m])
  51. else
  52. write (',',min,'-',a[m]);
  53. end;
  54. readln;
  55. readln;
  56.  
  57. end.
RAW Paste Data