fork download
  1. program ask(input, output);
  2.  
  3. const max=100000;
  4.  
  5. var n,c, i, count: integer;
  6. a: array[1..max] of integer;
  7. flag, fl: boolean;
  8.  
  9. begin
  10. readln(n);
  11.  
  12. for i:=1 to n do read(a[i]);
  13.  
  14. count:=0;
  15. i:=2;
  16. flag:=false;
  17. while not flag do
  18. begin
  19. while i<=n do
  20. begin
  21. if (a[i-1]>0) and (a[i]<0) then
  22. begin
  23. c:=a[i];
  24. a[i]:=a[i-1];
  25. a[i-1]:=c;
  26. count:=count+1;
  27. end;
  28. i:=i+1;
  29. end;
  30.  
  31. i:=2;
  32. fl:=true;
  33. while fl and (i<=n) do
  34. begin
  35. if (a[i-1]>0) and (a[i]<0) then
  36. begin
  37. c:=a[i];
  38. a[i]:=a[i-1];
  39. a[i-1]:=c;
  40. count:=count+1;
  41. fl:=false;
  42. end;
  43. i:=i+1;
  44. end;
  45.  
  46. if fl then flag:=true;
  47. end;
  48.  
  49. writeln(count);
  50. writeln(a[1]);
  51. writeln(a[n]);
  52. end.
Success #stdin #stdout 0.01s 4504KB
stdin
7
10 -9 -4 5 -2 3 8
stdout
4
-9
8