Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

WA得不明不白,谁帮我看看

Posted by My_loves at 2005-08-24 14:29:37 on Problem 1458
In Reply To:这题一个字符一个字符的读入会不会超时啊? Posted by:harrywy at 2005-08-24 13:34:11
program p1458;
 var common:array[0..500,0..500]of integer;
     st:array[1..2,1..10000]of char;
     len:array[1..2]of integer;

 procedure init;
  var s:char;
  begin
   repeat
    read(s);
    if (s=' ')  or (s=#13)or (s=#10)then break;
    inc(len[1]);
    st[1,len[1]]:=s;
   until false;
   repeat
    read(s);
   until (s=' ')  or (s=#13)or (s=#10);
   len[2]:=1;
   st[2,len[2]]:=s;
   repeat
    read(s);
    inc(len[2]);
    st[2,len[2]]:=s;
   until (s=' ')  or (s=#13)or (s=#10);
  end;

 procedure main;
  var i,j:integer;
  begin
   for i:=1 to len[1] do
    for j:=1 to len[2] do
     begin
      if st[1,i]=st[2,j] then common[i,j]:=common[i-1,j-1]+1
         else
          begin
           if common[i,j-1]>common[i-1,j] then common[i,j]:=common[i,j-1]
                                          else common[i,j]:=common[i-1,j];
          end;
     end
  end;

 begin
  repeat
   fillchar(len,sizeof(len),0);
   fillchar(common,sizeof(common),0);
   init;
   main;
   writeln(common[len[1],len[2]]);
  until eof;
 end.

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator