Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
93171 胡海峰老师 18岁生日 Python3 Compile Error 0 MS 0 KB 1412 2024-10-12 11:42:22

Tests(0/0):


Code:

#include <stdio.h> #include <stdlib.h> // 判断是否为闰年 int isLeapYear(int year) { return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); } // 获取月份的天数 int getDaysInMonth(int year, int month) { switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: return 31; case 4: case 6: case 9: case 11: return 30; case 2: return isLeapYear(year) ? 29 : 28; default: return 0; } } // 计算从出生到18岁生日的天数 int calculateDays(int year, int month, int day) { int days = 0; for (int i = year; i < year + 18; ++i) { for (int m = 1; m <= 12; ++m) { if (i == year && m < month) { continue; } if (i == year + 18 && m > month) { break; } days += getDaysInMonth(i, m); } } // 减去出生当天的天数 days -= (isLeapYear(year) && month > 2) ? 1 : 0; return days; } int main() { int T, year, month, day; scanf("%d", &T); while (T--) { scanf("%d-%d-%d", &year, &month, &day); int days = calculateDays(year, month, day); if (days <= 0) { printf("-1\n"); } else { printf("%d\n", days); } } return 0; }


Run Info:

  File "Main.py", line 4
    // \u5224\u65ad\u662f\u5426\u4e3a\u95f0\u5e74
     ^
SyntaxError: invalid syntax