[WA #1] why my code got WA #1
According to the discussion board.
I reference one code on here and change some thing.
But why still got the wrong answer.
I use the sample test to test.
The answer is right.
But when I upload to judgement.
Alway got the WA #1.
Someone can tell me why.
Thank you.
Below is my code.
#include<stdio.h>
#include<stdlib.h>
int is_leap_year(int y){
return ( ( y%4==0 ) && (y%100!=0||y%400==0) );
}
int days_per_year(int y){
if(is_leap_year(y))
return 366;
else
return 365;
}
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; /* Key point */
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);
int more_print = (day_begin + days)%7;
int i,j,flag;
flag = 0;
for(i=0;i<7;i++){
printf("%s",day_name[i]);
for(j=day_begin+i ; j <= days + more_print ; j+=7 )
if( j<1 || j>days )
printf("....");
else if(j==d){
flag = 1;
if(j<10)
printf("..[%d]",j);
else
printf("..[%2d]",j);
}
else{
if(j<day_begin+7){
if(flag){
printf("..%d",j);
flag = 0 ;
}
else{
printf("...%d",j);
}
}
else if(j >= day_begin+7 && j<10){
if(flag){
printf("...%d",j);
flag = 0 ;
}
else{
printf("....%d",j);
}
}
else if(j>=10 && j<= days){
if(flag){
printf("..%2d",j);
flag = 0 ;
}
else{
printf("...%2d",j);
}
}
else{
printf("....");
}
}/* if( j<1 || j>days ) */
printf("\n");
}/* for(i=0;i<7;i++) */
}
int main()
{
int d,m,y;
scanf("%d %d %d",&d,&m,&y);
if( y < 1600 || y > 2400) exit(0);
if( m < 1 || m > 12 ) exit(0);
if( d < 1 || d > 31 ) exit(0);
print_calendar(m,d,y);
exit (0);
}