zoukankan      html  css  js  c++  java
  • 分支-13. 计算天数(15)

    版权声明: https://blog.csdn.net/oFengWuYu1/article/details/27113033

    本题要求编敲代码计算某年某月某日是该年中的第几天。

    输入格式:

    输入在一行中依照格式“yyyy/mm/dd”(即“年/月/日”)给出日期。注意:闰年的判别条件是该年年份能被4整除但不能被100整除、或者能被400整除。

    闰年的2月有29天。

    输出格式:

    在一行输出日期是该年中的第几天。

    输入例子1:
    2009/03/02
    
    输出例子1:
    61
    
    输入例子2:
    2000/03/02
    
    输出例子2:

    62

    import java.util.Scanner;
    
    public class Main {
    
    	public static void main(String[] args) {
    		Scanner cin = new Scanner(System.in);
    		String str = cin.nextLine();
    		String[] strs = str.split("/");
    		int year = Integer.parseInt(strs[0]);
    		int month = Integer.parseInt(strs[1]);
    		int day = Integer.parseInt(strs[2]);
    		int[] months = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    		if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
    			months[1] = 29;
    		}
    		int result = 0;
    		for (int i = 0; i < month - 1; i++) {
    			result += months[i];
    		}
    		result += day;
    		System.out.print(result);
    	}
    }
    


    
                
查看全文
  • 相关阅读:
    poj 1328 Radar Installation (贪心)
    hdu 2037 今年暑假不AC (贪心)
    poj 2965 The Pilots Brothers' refrigerator (dfs)
    poj 1753 Flip Game (dfs)
    hdu 2838 Cow Sorting (树状数组)
    hdu 1058 Humble Numbers (DP)
    hdu 1069 Monkey and Banana (DP)
    hdu 1087 Super Jumping! Jumping! Jumping! (DP)
    必须知道的.NET FrameWork
    使用记事本+CSC编译程序
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10716327.html
  • Copyright © 2011-2022 走看看