自以为蛮简单的议题,没想到wa了好几次,re了好几次,还有一次ce。。。。
re的代码:
#include<stdio.h>
int main()
{
long days,temp,t;
int month[12],k,i,year;
char week[7][10]={"Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"};
char c[3],cc[3];//根源在这个数组,但不知道哪错了、、、
while(scanf("%ld",&days)!=EOF)
{
if(days==-1)
return 0;
t=days;
days++;
temp=0;
for(year=2000;days-temp>0;year++)
{
k=((year%4==0&&year%100!=0)||year%400==0)?366:365;
temp+=k;
}
year--;
if(days==temp)
{
printf("%d-12-31 %s/n",year,week[t%7]);
continue;
}
days-=(temp-k);
month[0]=31;
month[2]=31;
month[3]=30;
month[4]=31;
month[5]=30;
month[6]=31;
month[7]=31;
month[8]=30;
month[9]=31;
month[10]=30;
month[11]=31;
month[1]=(year%4==0&&year%100!=0)||year%400==0?29:28;
temp=0;
for(i=0;days-temp>0;i++)
{
k=month[i];
temp+=k;
}
if(i/10==0)
{
c[0]='0';
c[1]=i+'0';
}
else if(i/10>0)
{
c[0]=i/10+'0';
c[1]=i%10+'0';
}
c[2]='/0';
if(days==temp)
{
printf("%d-%s-%s %s/n",year,c,month[i-1],week[t%7]); /*printf("%d-%s-%s %s/n",year,c,month[i- 1],week[t%7]); month[i-1]是整型,其输出格式
应是%d。原来写为%s时,将把month[i-1]的内容
作为字符串指针,所以出现RE.*/
continue;
}
days-=(temp-k);
if(days/10==0)
{
cc[0]='0';
cc[1]=days+'0';
}
else if(days/10>0)
{
cc[0]=days/10+'0';
cc[1]=days%10+'0';
}
cc[2]='/0';
printf("%d-%s-%s %s/n",year,c,cc,week[t%7]);
}
return 0;
}