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 1201. Which Day Is It?

what's wrong in this code??????????!!!!!!!!!!!!!
Posted by James 16 Mar 2002 20:06
Program which_day_is_it;
 const
   month1:array[1..12] of byte=(31,28,31,30,31,30,31,31,30,31,30,31);
   week1:array[1..7] of string[3]=
('mon','tue','wed','thu','fri','sat','sun');
 var
   y,m,d:longint;
   i,j,k,l,yy,mm,dd,weekday1,days,last:longint;
   r:array[1..7,1..6] of longint;
   v:array[1..7] of longint;

Begin
  readln(d,m,y);
  weekday1:=5;
  for i:=1600 to y-1 do
   begin
     k:=0;
     if (i mod 400=0) or (i mod 100<>0) and (i mod 4=0) then k:=1;
     weekday1:=(weekday1+1+k) mod 7;
   end;
  inc(weekday1); if weekday1=7 then weekday1:=0;
  if (y mod 400=0) or (y mod 100<>0) and (y mod 4=0) then k:=1 else
k:=0;
  for i:=1 to m-1 do
   if i=2 then weekday1:=(weekday1+28+k) mod 7
    else weekday1:=(weekday1+month1[i]) mod 7;
  if weekday1=0 then weekday1:=7;
  if (y mod 400=0) or (y mod 100<>0) and (y mod 4=0) then k:=1 else
k:=0;
  days:=month1[m]; if m=2 then days:=days+k;
  fillchar(r,sizeof(r),0);
  fillchar(v,sizeof(v),0);
  r[weekday1,1]:=1; v[weekday1]:=1; j:=weekday1;
  for i:=1 to weekday1-1 do v[i]:=1;
  for i:=2 to days do
   begin
     inc(j); if j=8 then j:=1;
     inc(v[j]);
     r[j,v[j]]:=i;
   end;
  k:=0;
  for i:=1 to 7 do
   begin
     k:=0;
     write(week1[i]);
     for j:=1 to v[i] do
      if r[i,j]=0 then write('    ')
       else if r[i,j]=d then
             begin
               k:=1;
               if (r[7,j]>9) or (r[i,j]>9) then
                begin
                  if r[i,j]>9 then
                   write('  [',r[i,j],']')
                  else
                   write('   [',r[i,j],']');
                end
               else
                begin
                  if r[i,j]>9 then
                   write(' [',r[i,j],']')
                  else write('  [',r[i,j],']');
                end;
             end
        else if (r[7,j]>9) or (r[i,j]>9) then
              if k=1 then begin write(r[i,j]:4); k:=0; end
               else write(r[i,j]:5)
              else if k=1 then begin write(r[i,j]:3); k:=0; end
               else write(r[i,j]:4);
     writeln;
   end;
End.