Advertisement
tuki2501

daydondieu

Sep 6th, 2018
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.92 KB | None | 0 0
  1. uses crt;
  2. var
  3.   a:array[1..100] of longint;
  4.   i,n,x,y:longint;
  5.  
  6. function check(bool:boolean):longint;
  7. var tmp,max:longint;
  8. begin
  9.   tmp:=1;
  10.   max:=1;
  11.   for i:=2 to n do
  12.     if ((a[i] > a[i-1] = bool) or (a[i] = a[i-1])) then
  13.       begin
  14.         inc(tmp);
  15.         if tmp>max then max:=tmp;
  16.       end
  17.     else tmp:=1;
  18.   check:=max;
  19. end;
  20.  
  21. procedure sort(bool:boolean);
  22. var j,temp:longint;
  23. begin
  24.   for i:=1 to n do
  25.     for j:=i+1 to n do
  26.       if ((a[i] > a[j] = bool) or (a[i] = a[j])) then
  27.         begin
  28.           temp:=a[i];
  29.           a[i]:=a[j];
  30.           a[j]:=temp;
  31.         end;
  32. end;
  33.  
  34. procedure rwArray(bool:boolean);
  35. begin
  36.   if bool then readln(n);
  37.   for i:=1 to n do
  38.     if bool then read(a[i])
  39.     else write(a[i],' ');
  40.   if bool then readln();
  41. end;
  42.  
  43. begin
  44.   clrscr();
  45.  
  46.   rwArray(true);
  47.   x:=check(true);
  48.   y:=check(false);
  49.   if x<>y then sort(x>y);
  50.   rwArray(false);
  51.  
  52.   readln();
  53. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement