文章
79
粉丝
221
获赞
46
访问
198.4k
#include <iostream>
using namespace std;
typedef struct Data {
int y, m, d;
}dat;
bool Jud(int year) {
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
int main() {
dat p;
while (cin>>p.y>>p.m>>p.d) {
int flag = Jud(p.y), sum = 0;
if (p.y < 1 || p.m < 1 || p.m>12 || p.d < 1 || p.d>31 || ((p.m < 8 && p.m % 2 == 0 || p.m >= 8 && p.m % 2 != 0) && p.d > 30) || (flag == 0 && p.m == 2 && p.d > 28) || (p.m == 2 && p.d > 29)) {
cout << "Input error!"<<endl;
continue;
}
for (int i = 1; i < p.m; i++) {
if (i == 2) {
sum += flag ? 29 : 28;
continue;
}
sum += i < 8 && i % 2 == 0 || i >= 8 && i % 2 != 0 ? 30 : 31;
}
sum += p.d;
cout <<sum<<endl;
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发