解题思路:
import java.util.Scanner; public class C1246 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String[] a = sc.nextLine().split("/"); F(Integer.valueOf(a[0]), Integer.valueOf(a[1]), Integer.valueOf(a[2])); } sc.close(); } private static void F(int year, int month, int day){ boolean isLeap = (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)); int d = day; for(int m = 1; m < month; m++) d += getMonthDay(isLeap, m); System.out.println(d); } private static int getMonthDay(boolean isLeap, int month) { switch(month){ case 4: case 6: case 9: case 11: return 30; case 2: return isLeap ? 29 : 28; } return 31; } }
注意事项:
参考代码:
0.0分
0 人评分
C语言训练-数字母 (C语言代码)浏览:649 |
完数 (C语言代码)浏览:693 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:531 |
星期判断机 (C语言代码)浏览:859 |
C语言程序设计教程(第三版)课后习题9.8 (C语言代码)浏览:615 |
Pascal三角 (C语言代码)浏览:651 |
C语言程序设计教程(第三版)课后习题12.3 (C语言代码)浏览:547 |
C语言程序设计教程(第三版)课后习题6.10 (C语言代码)浏览:512 |
C语言程序设计教程(第三版)课后习题10.7 指针(C语言代码)浏览:545 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:444 |