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?

Who can paste an AC program to all us ?
Posted by lyj_george 28 Jun 2002 19:11
We can know all where we made mistakes.
AC program inside. In fact, there can be trailing spaces before end of lines.
Posted by Han Wentao 1 Aug 2002 20:25
#include <iostream>
using namespace std;
inline bool is_leap_year(int y)
{
    return y%4==0&&(y%100!=0||y%400==0);
}
inline int days_per_year(int y)
{
    if(is_leap_year(y))
        return 366;
    else
        return 365;
}
inline int days_per_month(int m,int y)
{
    const int days[12]={31,28,31,30,31,30,31,31,30,31,30,31};
    if(m!=2)
        return days[m-1];
    else if(is_leap_year(y))
        return 29;
    else
        return 28;
}
int get_day_of_week(int m,int d,int y)
{
    int day=4;
    int i;
    for(i=1600;i<y;i++)
        day+=days_per_year(i);
    for(i=1;i<m;i++)
        day+=days_per_month(i,y);
    day+=d;
    return day%7;
}
void print_calendar(int m,int d,int y)
{
    const char* day_name[7]=
{"mon","tue","wed","thu","fri","sat","sun"};
    int days=days_per_month(m,y);
    int day_begin=1-get_day_of_week(m,1,y);
    for(int i=0;i<7;i++)
    {
        cout<<day_name[i];
        for(int j=day_begin+i;j<=days;j+=7)
            if(j<1||j>days)
                cout<<"     ";
            else if(j==d)
            {
                if(j<10)
                    cout<<" [ "<<j<<"]";
                else
                    cout<<" ["<<j<<"]";
            }
            else
            {
                if(j<10)
                    cout<<"   "<<j<<" ";
                else
                    cout<<"  "<<j<<" ";
            }
        cout<<endl;
    }
}
int main()
{
    int d,m,y;
    cin>>d>>m>>y;
    print_calendar(m,d,y);
    return 0;
}