文章
40
粉丝
607
获赞
68
访问
419.5k
#include <iostream>
using namespace std;
typedef struct Time {
int year;
int month;
int day;
}Time;
int a[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };//平年
int b[13] = { 0,31,29,31,30,31,30,31,31,30,31,30,31 };//闰年
int main() {
Time time;
int sum = 0;
while (cin >> time.year >> time.month >> time.day) {
if (time.month > 12 || time.month < 1) {//输入month正确性
cout << "Input error!"<<endl;
continue;
}
if (time.year % 4 == 0 && time.year % 100 != 0 || time.year % 400 == 0) {//判断是否为闰年
if (time.day > b[time.month] || time.day < 1)//输入day正确性
{
cout << "Input error!"<<endl;
continue;
}
for (int i = 0;i < time.month;i++) {//计算天数
sum = sum + b[i];
}
sum = sum + time.day;
}
else {
if (time.day > a[time.month]|| time.day < 1 )//输入day正确性
{
cout << "Input error!"<<endl;
continue;
}
for (int i =...
登录后发布评论
暂无评论,来抢沙发