计算天数.c 447 B

12345678910111213141516171819202122
  1. #include <stdio.h>
  2. int main() {
  3. int year, month, day;
  4. scanf("%d %d %d", &year, &month, &day);
  5. int result = day, i;
  6. for(i = 1; i < month; i++) {
  7. if (year % 4 == 0 && i == 2) result += 29;
  8. else {
  9. switch(i) {
  10. case 1: case 3: case 5: case 7: case 8: case 10: case 12: result += 31; break;
  11. case 2: result += 28; break;
  12. case 4: case 6: case 9: case 11: result += 30; break;
  13. }
  14. }
  15. }
  16. printf("%d", result);
  17. return 0;
  18. }