//#include "stdafx.h"
#include <iostream>
using namespace std;
bool isLeapYear(unsigned int year) {
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
return true;
}
else {
return false;
}
}
int getDays(unsigned int year, unsigned int month, unsigned int day) {
if (month == 0 || month > 12 || day == 0 || day > 31) {
return -1;
}
int days = 0;//天数
switch (month - 1) {//累加本月之前的天数
case 11:
days += 30;
case 10:
days += 31;
case 9:
days += 30;
case 8:
days += 31;
case 7:
days += 31;
case 6:
days += 30;
case 5:
days += 31;
case 4:
days += 30;
case 3:
days += 31;
case 2:
days += isLeapYear(year) == true ? 29 : 28;//若是闰年则+ 29,否则+ 28
case 1:
days += 31;
}
days += day;//加上本月天数
return days;
}
int main() {
int n = 0;
cin >> n;
while (n--) {
unsigned int year = 0;
unsigned int month = 0;
unsigned int day = 0;
cin >> year >> month >> day;
cout << getDays(year, month, day) << endl;
}
//system("pause");
return 0;
}
ACM日期计算(C++实现):输入一个日期,格式如:2010 10 24 ,判断这一天是这一年中的第几天。
最新推荐文章于 2023-03-22 08:19:45 发布