您的位置:首页 > 职场人生

牛客网编程练习之编程马拉松:程序员日

2017-12-11 02:07 267 查看

 

AC代码:

import java.util.Scanner;

/**
* @author CC11001100
*/
public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
while (sc.hasNextLine()){
String[] ss = sc.nextLine().split("-");
int y = Integer.parseInt(ss[0]);
int m = Integer.parseInt(ss[1]);
int d = Integer.parseInt(ss[2]);
System.out.println(dayCount(y, m, d));
}

}

private static int[] month = new int[]{
31, // 1
-1, // 2
31, // 3
30, // 4
31, // 5
30, // 6
31, // 7
31, // 8
30, // 9
31, // 10
30, // 11
31, // 12
};

private static int dayCount(int y, int m, int d){
int res = d;
for(int i=0; i<m-1; i++){
if(i==1) res += (y%4==0 && y%100!=0 || y%400==0) ? 29 : 28;
else res += month[i];
}
return res;
}

}

 

题目来源: https://www.nowcoder.com/practice/973d4b33811c4d8c9ed1e4b249765714?tpId=3&tqId=10941&tPage=1&rp=&ru=/ta/hackathon&qru=/ta/hackathon/question-ranking

 

.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: