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);
    	}
    }
    


    
                
查看全文
  • 相关阅读:
    python代写主题LDA建模和t-SNE可视化
    Python代写LDA主题模型算法应用
    R语言代写之文本分析:主题建模LDA
    Python代写商品数据预处理与K-Means聚类可视化分析
    matlab代写使用Copula仿真优化市场风险
    BZOJ 5495: [2019省队联测]异或粽子 可持久化trie+堆
    BZOJ 3689: 异或之 可持久化trie+堆
    BZOJ 4212: 神牛的养成计划 可持久化trie+trie
    BZOJ 2006: [NOI2010]超级钢琴 ST表+堆
    BZOJ 4103: [Thu Summer Camp 2015]异或运算 可持久化trie
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10716327.html
  • Copyright © 2011-2022 走看看