ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1723. Sandro's Book

I've got WA #7. Help me, please!
Posted by felfer 14 Dec 2011 01:36
const N=50;
type TChastot=array [1..N] of byte;

var inStr,outStr:string; chast:TChastot;
    i,j:integer;  maxChast,iPos:integer;

begin
  readln(inStr);
  for i:=1 to length(inStr) do
  begin
    chast[i]:=0;
    for j:=i to length(inStr) do
      if inStr[i]=inStr[j] then
        chast[i]:=chast[i]+1;
  end;
  maxChast:=Low(integer); iPos:=0;
  for i:=1 to length(inStr) do
    if maxChast<chast[i] then
    begin
     maxChast:=chast[i];
     iPos:=i;
    end;
  i:=iPos; outStr:='';
  while (i<=length(inStr)) and (chast[i]=chast[iPos]) do
  begin
   outStr:=outStr+inStr[i];
   i:=i+1;
  end;
  if length(outStr)<length(inStr) then
  begin
   i:=pos(outStr,copy(inStr,length(outStr)+1,length(inStr)-length(outStr)));
   while i=0 do
   begin
    delete(outStr,length(outStr),1);
    i:=pos(outStr,copy(inStr,length(outStr)+1,length(inStr)-length(outStr)));
   end;
  end;
  writeln(outStr);
end.

Edited by author 14.12.2011 02:20