1.13 32:日历问题

1

2000-01-02 Sunday

#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
int monthdays[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
string weeks[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
bool isLeap(int year);
string getWeek(int year, int month, int day);
int main()
{
int year=2000, month=1, day, days,round,temp;
string week;
scanf("%d",&days);
days++;
while(1)
{
if(isLeap(year))
{
if(days-366>0)
{
year++;
days -= 366;
}else
{
break;
}
}else
{
if(days-365>0)
{
year++;
days -= 365;
}else
{
break;
}
}
}
switch(month)
{
case 1:
if(days-31<0)
{
month=1;
break;
}
days-=31;
case 2:
if(days-28<0)
{
month=2;
break;
}
if(isLeap(year))
{
if(days-29<0)
{
month=2;
break;
}
days--;
}
days-=28;
case 3:
if(days-31<0)
{
month=3;
break;
}
days-=31;
case 4:
if(days-30<0)
{
month=4;
break;
}
days-=30;
case 5:
if(days-31<0)
{
month=5;
break;
}
days-=31;
case 6:
if(days-30<0)
{
month=6;
break;
}
days-=30;
case 7:
if(days-31<0)
{
month=7;
break;
}
days-=31;
case 8:
if(days-31<0)
{
month=8;
break;
}
days-=31;
case 9:
if(days-30<0)
{
month=9;
break;
}
days-=30;
case 10:
if(days-31<0)
{
month=10;
break;
}
days-=31;
case 11:
if(days-30<0)
{
month=11;
break;
}
days-=30;
case 12:
month=12;
}
day = days;
week = getWeek(year,month,day);
cout<<year<<"-";
if(month<10)
cout<<"0";
cout<<month<<"-";
if(day<10)
{
cout<<0;
}
cout<<day<<" ";
cout<<week<<endl;
return 0;
}
bool isLeap(int year)
{
if(year%4==0 && (year%100!=0 || year%400==0))
{
return true;
}
return false;
}
string getWeek(int year, int month, int day)
{
int days=day,week;
for(int i=1900;i<year;i++)
{
if(isLeap(i))
{
days += 366;
}else
{
days += 365;
}
}
for(int i=1;i<month;i++)
{
days+=monthdays[i-1];
}
if(month > 2 && isLeap(year))
{			days++;
}
week = days%7;
return weeks[week];
}

• 点赞
• 评论
• 分享
x

海报分享

扫一扫，分享海报

• 收藏
• 打赏

打赏

yansuifeng1126

你的鼓励将是我创作的最大动力

C币 余额
2C币 4C币 6C币 10C币 20C币 50C币
• 举报
• 一键三连

点赞Mark关注该博主, 随时了解TA的最新博文

03-11 1032
05-11 686
03-11 1007
07-12 452
05-02 30
08-28 1781
10-19 5万+
04-13 1万+
04-23