ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1201. Какой сегодня день?

What's going wrong??? Program 100% tested, and I can't find errors in output
Послано Daeman 11 сен 2002 23:03
I can't understand what's going on... :( Tested this thouslands of
times using windows calendar, got WA :( This seems to output all
correctly (dots are spaces, everything is aligned, even 1-digit
numbers, date is highlighned by square brackets). Ppl plz help!


=================================[Cut]=============================
program WhichDayIsIt;

const DaysOfWeek: array[1..7] of String[3] = (
        'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'
      );

function YearLength(Year: Integer): Integer;
begin
  if ((Year mod 4 = 0) and (Year mod 100 <> 0)) or (Year mod 1000 =
0) then
    YearLength := 366
  else
    YearLength:= 365;
end;

function MonthLength(Month, Year: Integer): Integer;
begin
  case Month of
    1, 3, 5, 7, 8, 10, 12: MonthLength := 31;
    2: if YearLength(Year) = 365 then MonthLength := 28 else
MonthLength := 29;
  else
    MonthLength := 30;
  end;
end;

function Delta(Day, Month, Year: Integer): Integer;
var i, Temp: Integer;
begin
  Temp := 0;
  for i := 1600 to (Year - 1) do
    Temp := Temp + YearLength(i);
  for i := 1 to (Month - 1) do
    Temp := Temp + MonthLength(i, Year);
  Temp := Temp + Day - 1;
  Delta := Temp;
end;

function DOW(Day, Month, Year: Integer): Byte;
begin
  DOW := (Delta(Day, Month, Year) + 3) mod 7 + 1;
end;

function IntToStr2(i: Integer): String;
var St: String;
begin
  Str(i, St);
  if Length(St) < 2 then St := ' ' + St;
  IntToStr2 := St;
end;

var Day, Month, Year: Integer;
    i, DW: Integer;
    Out: array[1..7] of string;
begin
  Read(Day, Month, Year);
  DW := DOW(1, Month, Year);
  for i := 1 to 7 do
  begin
    Out[i] := DaysOfWeek[i] + ' ';
    if i < DW then
      Out[i] := Out[i] + '    ';
  end;
  for i := 1 to MonthLength(Month, Year) do
  begin
    if i = Day then
      Out[(i + DW - 2) mod 7 + 1] := Out[(i + DW - 2) mod 7 + 1]
+ '[' + IntToStr2(i) + ']'
    else
      Out[(i + DW - 2) mod 7 + 1] := Out[(i + DW - 2) mod 7 + 1]
+ ' ' + IntToStr2(i) + ' ';
  end;
  for i := 1 to 7 do
    WriteLn(Out[i]);
end.
====================================[Cut]===========================
Re: What's going wrong??? Program 100% tested, and I can't find errors in output
Послано Flyer 14 сен 2002 18:40
 See discussing: http://acm.timus.ru/messages.asp?id=4330.
 Don't write "[1]", but write [ 1]!!!