题解 | #计算日期到天数转换#
计算日期到天数转换
https://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
//暴力算法 #include <iostream> #include <vector> using namespace std; int main() { int a; vector<int> date; while (cin >> a) { // 注意 while 处理多个 case date.push_back(a); } int num = 0; if (date[0] % 400 == 0 ||(date[0] % 4 ==0 && date[0] % 100 != 0)) { if (date[1] < 10) { int month = date[1] % 10; if (month == 1) { num = date[2]; } else if (month == 2) { num = 31 + date[2]; } else if (month == 3) { num = 31 + 29 + date[2]; } else if (month == 4) { num = 31 + 29 + 31 + date[2]; } else if (month == 5) { num = 31 + 29 + 31 + 30 + date[2]; } else if (month == 6) { num = 31 + 29 + 31 + 30 + 31 + date[2]; } else if (month == 7) { num = 31 + 29 + 31 + 30 + 31 + 30 + date[2]; } else if (month == 8) { num = 31 + 29 + 31 + 30 + 31 + 30 + 31 + date[2]; } else if (month == 9) { num = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + date[2]; } } else { int month = date[1] - 10; if (month == 0) { num = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + date[2]; } else if (month == 1) { num = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + date[2]; } else if (month == 2) { num = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + date[2]; } } } else { if (date[1] < 10) { int month = date[1] % 10; if (month == 1) { num = date[2]; } else if (month == 2) { num = 31 + date[2]; } else if (month == 3) { num = 31 + 28 + date[2]; } else if (month == 4) { num = 31 + 28 + 31 + date[2]; } else if (month == 5) { num = 31 + 28 + 31 + 30 + date[2]; } else if (month == 6) { num = 31 + 28 + 31 + 30 + 31 + date[2]; } else if (month == 7) { num = 31 + 28 + 31 + 30 + 31 + 30 + date[2]; } else if (month == 8) { num = 31 + 28 + 31 + 30 + 31 + 30 + 31 + date[2]; } else if (month == 9) { num = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + date[2]; } } else { int month = date[1] - 10; if (month == 0) { num = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + date[2]; } else if (month == 1) { num = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + date[2]; } else if (month == 2) { num = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + date[2]; } } } cout << num ; } // 64 位输出请用 printf("%lld")