Advertisement
finalshare

Substraightstring.pas

Jul 26th, 2015
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.97 KB | None | 0 0
  1. //Do phuc tap O(n)
  2. var
  3.     fi,fo:text;
  4.     k,i,j,n,dem,max:longint;
  5.     a: array [1..1000000] of longint;
  6.     check:boolean;
  7. begin
  8.     assign(fi,'INPUT.INP');
  9.     assign(fo,'OUTPUT.OUT');
  10.     reset(fi);
  11.     rewrite(fo);
  12.     readln(fi,n);
  13.     for i:=1 to n do
  14.     read(fi,a[i]);
  15.     i:=0;
  16.     max:=0;
  17.     while i<=(n-2) do
  18.         begin
  19.             inc(i);
  20.             dem:=1;
  21.             if (a[i] = a[i+1]) and (i < n) then //Tim thay truong hop thoa man
  22.                 while ( a[i] = a[i+1] ) and ( i<n ) do
  23.                     begin
  24.                         inc(i);
  25.                         dem:=dem+1;
  26.                     end;
  27.             if dem>max then max:= dem;
  28.         end;
  29.     if max < 2 then //Max = 1 , Max=0 thi STOP
  30.         begin
  31.             write(fo,'KHONG TON TAI');
  32.             close(fo);
  33.             close(fi);
  34.             exit;
  35.         end;
  36.         write(fo,max);
  37.         writeln(fo);
  38.     for i:=1 to n-max+1 do
  39.     begin
  40.         check:=true;
  41.         for j:=i to i+max-2 do
  42.             if (a[j]<>a[j+1]) and (j<n) then check:=false;
  43.         if check then
  44.             for k:=i to i+max-1 do write(fo,a[k],' ');
  45.         if check then
  46.             writeln(fo);
  47.     end;
  48.     close(fi);
  49.     close(fo);
  50. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement