私信TA

用户名:Praguetramp

访问量:29548

签 名:

等  级
排  名 19
经  验 19970
参赛次数 0
文章发表 130
年  龄 0
在职情况 待业
学  校
专  业

  自我简介:

aura

解题思路:  数组计数

注意事项:  注意区分闰年的情况

参考代码:

import java.util.Scanner;

/**
 * 2021年2月16日  下午8:32:46
 * @author praguetramp
 */
public class Main {
	public static void main(String []args) {
		Scanner in =new Scanner(System.in);
		int arr[][]=new int[][] {{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};
		while(in.hasNext()) {
			String date[] = in.nextLine().split("/");
			int cnt=0;
			int y=Integer.parseInt(date[0]),m=Integer.parseInt(date[1]),d=Integer.parseInt(date[2]);
			if(y%400==0||y%4==0&&y%100!=0)
				for(int i=0;i<m;i++)
					cnt+=arr[1][i];
			else
				for(int i=0;i<m;i++)
					cnt+=arr[0][i];
			System.out.println(cnt+d);
		}
		in.close();
	}
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区