九度题目1043

2016-12-02 12:52:10来源:网络收集作者:IT狂人人点击

第七城市
#include
#include
#define run(x) x%100!=0&&x%4==0||x%400==0?1:0
int daysofmonth[13][2]={
0,0,
31,31,
28,29,
31,31,
30,30,
31,31,
30,30,
31,31,
31,31,
30,30,
31,31,
30,30,
31,31
};
struct Date{
int Day,Month,Year;
void nextday(){
Day++;
if(Day>daysofmonth[Month][run(Year)]){
Day=1;
Month++;
if(Month>12){
Month=1;
Year++;
}
}
}
};
int buf[3001][13][32];
char month[13][20]={
"",
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
char dayofweek[7][20]={
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
};
int main(){
int cnt=0;
Date a;
a.Day=1;
a.Month=1;
a.Year=0;
while(a.Year<3001){
buf[a.Year][a.Month][a.Day]=cnt;
a.nextday();
cnt++;
}
int d,m,y;
char ms[20];
while(scanf("%d%s%d",&d,&ms,&y)!=EOF){
for(m=1;m<=12;m++){
if(strcmp(ms,month[m])==0){
break;
}
}
int n=buf[y][m][d]-buf[2016][2][21];
n=n+0;
puts(dayofweek[(n%7+7)%7]);
}
return 0;

}


注意:


1.判断两个字符串是否相同,使用strcmp(a,b)==0


2.for循环里面的if中写break


3.(n%7+7)%7保证下标为正 且兼顾了日期在前在后的问题


4.puts函数的使用,就是用来输出字符串的,且换行,等效于printf(“%s/n”,s)


5.注意引用时候名称的正确拼写

第七城市

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台