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?

WA#6 Why?
Posted by He Xing Zhou 7 Aug 2006 02:31
This is my program (Written in C++):

#include <iostream>

using namespace std;

int day(int yy,int mm)
{
    int s=0;
    if (mm==1) s=31;
    if (mm==2)
    {
           if (yy%100==0 && (yy>1918 || (yy==1918 && mm>=2)))
               {if (yy%400==0) s=29; else s=28;}
           else
               {if (yy%4==0) s=29; else s=28;}
    }
    if (mm==3) s=31;
    if (mm==4) s=30;
    if (mm==5) s=31;
    if (mm==6) s=30;
    if (mm==7) s=31;
    if (mm==8) s=31;
    if (mm==9) s=30;
    if (mm==10) s=31;
    if (mm==11) s=30;
    if (mm==12) s=31;
    return s;
}

int week(int yyyy,int mm)
{
    int i,j;long long s;
    s=1;
    if (yyyy>1918 || (yyyy==1918 && mm>=2)) j=1918; else
    j=1600;
    for (i=j;i<yyyy;i++)
       {
           if (i%100==0 && (yyyy>1918 || (yyyy==1918 && mm>=2)))
               {if (i%400==0) s=s+366; else s=s+365;}
           else
               {if (i%4==0) s=s+366; else s=s+365;}
       }
    for (i=1;i<mm;i++)
        s=s+day(yyyy,i);
    return s%7;
}

void print(int da,int wek,int dd,int yyyy,int mm)
{
     int a[7][6],i,j;
     for (i=0;i<7;i++)
         for (j=0;j<6;j++)
             a[i][j]=0;
     int x=wek,y=0,z=6;
     for (i=1;i<=da;i++)
     {
         if (yyyy==1918 && mm==2 && i==1) {i=14;x=3;}
         a[x][y]=i;
         if (x==6) {x=0;y++;} else x++;
     }
     if (a[0][5]==0 && a[6][5]==0) z--;
     if (a[0][4]==0 && a[6][4]==0) z--;
     if (a[0][3]==0 && a[6][3]==0) z--;
     for (i=0;i<7;i++)
     {
         switch (i){
                case 0:cout<<"mon";break;
                case 1:cout<<"tue";break;
                case 2:cout<<"wed";break;
                case 3:cout<<"thu";break;
                case 4:cout<<"fri";break;
                case 5:cout<<"sat";break;
                case 6:cout<<"sun";break;
                }
         for (j=0;j<z;j++)
         {
             if (a[i][j]>0 || j<z-1) cout<<" ";
             if (a[i][j]==dd) cout<<"["; else if (a[i][j]>0 || j<z-1 )cout<<" ";
             if (a[i][j]==0 && j<z-1) cout<<"  ";
             if (a[i][j]<10 && a[i][j]>0) cout<<" "<<a[i][j];
             if (a[i][j]>9) cout<<a[i][j];
             if (a[i][j]==dd) cout<<"]"; else if (a[i][j+1]>0 && j<z-1) cout<<" ";
         }
         cout<<endl;
     }
     return;
 }

int main()
{
    int dd,mm,yyyy;
    cin>>dd>>mm>>yyyy;
    print(day(yyyy,mm),week(yyyy,mm),dd,yyyy,mm);
    system("PAUSE");
    return 0;
}

I have found the diffence between before February, 1918 and after. But when the #6 test. I have wrong answer. Why?
(In February 1918, there are only 14th to 28th, Is that right?)