Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Do phuc tap O(n)
- var
- fi,fo:text;
- k,i,j,n,dem,max:longint;
- a: array [1..1000000] of longint;
- check:boolean;
- begin
- assign(fi,'INPUT.INP');
- assign(fo,'OUTPUT.OUT');
- reset(fi);
- rewrite(fo);
- readln(fi,n);
- for i:=1 to n do
- read(fi,a[i]);
- i:=0;
- max:=0;
- while i<=(n-2) do
- begin
- inc(i);
- dem:=1;
- if (a[i] = a[i+1]) and (i < n) then //Tim thay truong hop thoa man
- while ( a[i] = a[i+1] ) and ( i<n ) do
- begin
- inc(i);
- dem:=dem+1;
- end;
- if dem>max then max:= dem;
- end;
- if max < 2 then //Max = 1 , Max=0 thi STOP
- begin
- write(fo,'KHONG TON TAI');
- close(fo);
- close(fi);
- exit;
- end;
- write(fo,max);
- writeln(fo);
- for i:=1 to n-max+1 do
- begin
- check:=true;
- for j:=i to i+max-2 do
- if (a[j]<>a[j+1]) and (j<n) then check:=false;
- if check then
- for k:=i to i+max-1 do write(fo,a[k],' ');
- if check then
- writeln(fo);
- end;
- close(fi);
- close(fo);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement