杭电 2005 ( 第几天? ) java

来源:互联网 发布:净化网络环境的意义 编辑:程序博客网 时间:2024/06/16 17:51
import java.util.Scanner;public class Main {    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        int d[] = {0, 31, 28, 31, 30, 31, 30, 31, 30, 31, 30, 31};        while (sc.hasNext()) {            String s = sc.next();            int days = 0;            int year, month, day;            String[] str = s.split("/");            year = Integer.parseInt(str[0]);            month = Integer.parseInt(str[1]);            day = Integer.parseInt(str[2]);            if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0) && month > 2) {                days++;            }            for (int i = 0; i < month; i++) {                days = days + d[i];            }            days += day;            System.out.println(days);        }    }}

0 0