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

help me. >> WA 2 <<
Posted by John Mac 7 Jul 2011 13:15
this my code:


var
  a,b,s,ms:string[50];
  ss,mss,k,n,i,j:integer;
begin
  readln(s);
  n:=length(s);
  mss:=0;
  for i := 2 to n div 2 do
    for j := 1 to n-i-1 do
      begin
        a:=copy(s,j,i);
        ss:=1;
        for k := j+1 to n-i+1 do
          begin
            b:=copy(s,k,i);
            if a=b then inc(ss,1);
          end;
        if mss<=ss then
        begin
          mss:=ss;
          ms:=a;
        end;
      end;
  if mss=1 then write(s) else write(ms);
end.

OR


var
  a,b,s,ms:string[50];
  ss,mss,k,n,i,j:integer;
begin
  readln(s);
  n:=length(s);
  mss:=0;
  for i := 2 to n div 2 do
    for j := 1 to n-i-1 do
      begin
        a:=copy(s,j,i);
        ss:=1;
        for k := j+1 to n-i+1 do
          begin
            b:=copy(s,k,i);
            if a=b then inc(ss,1);
          end;
        if mss<=ss then
        begin
          mss:=ss;
          ms:=a;
        end;
      end;
  write(ms);
end.
Re: help me. >> WA 2 <<
Posted by [RSU_Tash]Nodirbek_Kuklamov 16 Nov 2011 00:42
Simple: start your cycle for i from 1.