web123456

【C++】Compiling date to day conversion

#include <iostream> using namespace std; int main() { static int monthdays[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int year, month, day; while (cin >> year >> month >> day) { // Note while handling multiple cases // If you use while, you can continuously receive input; press ctrl + c to end the loop. int n = 0; //Calculate the number of days in 1-month-1 month for (int i = 1; i < month; i++) { n += monthdays[i]; } //Accumulate the number of days in that month n += day; //If it is a leap year, add 1; if (month > 2 &&((year % 4 == 0 && year % 100 != 0 ) || (year % 400 == 0))) { n += 1; } cout << n << endl; } return 0; } // Please use printf("%lld") for 64-bit output