QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#656124 | #7176. I Flipped The Calendar... | LanFey | WA | 0ms | 3644kb | C++23 | 1.2kb | 2024-10-19 11:27:30 | 2024-10-19 11:27:34 |
Judging History
answer
#include <iostream>
using namespace std;
// Helper function to check if a year is a leap year
bool isLeapYear(int year) {
if (year % 400 == 0) return true;
if (year % 100 == 0) return false;
return (year % 4 == 0);
}
// Function to calculate the total number of rows in the calendar for the given year
int countCalendarRows(int year) {
// Days in each month (index 0 = January, 11 = December)
int daysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
// Adjust February for leap year
if (isLeapYear(year)) daysInMonth[1] = 29;
int totalRows = 0;
int currentDayOfWeek = 0; // Monday = 0 (January 1 starts on a Monday in this example)
for (int month = 0; month < 12; ++month) {
int days = daysInMonth[month];
// Calculate the number of rows required for this month
int rows = (days + currentDayOfWeek + 6) / 7;
totalRows += rows;
// Update the starting day of the next month
currentDayOfWeek = (currentDayOfWeek + days) % 7;
}
return totalRows;
}
int main() {
int year;
cin >> year;
cout << countCalendarRows(year) << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3520kb
input:
2023
output:
63
result:
ok 1 number(s): "63"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
1970
output:
63
result:
ok 1 number(s): "63"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3644kb
input:
1971
output:
63
result:
wrong answer 1st numbers differ - expected: '61', found: '63'