博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDOJ 1076 An Easy Task(闰年计算)
阅读量:7198 次
发布时间:2019-06-29

本文共 1255 字,大约阅读时间需要 4 分钟。

Problem Description

Ignatius was born in a leap year, so he want to know when he could hold his birthday party. Can you tell him?

Given a positive integers Y which indicate the start year, and a positive integer N, your task is to tell the Nth leap year from year Y.

Note: if year Y is a leap year, then the 1st leap year is year Y.

Input

The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains two positive integers Y and N(1<=N<=10000).

Output

For each test case, you should output the Nth leap year from year Y.

Sample Input

3
2005 25
1855 12
2004 10000

Sample Output

2108
1904
43236

Hint:

We call year Y a leap year only if (Y%4==0 && Y%100!=0) or Y%400==0.

题意就是:输入一个年份year和一个n,求这个year之后的第n个闰年,

如果year是闰年,则算第一个闰年。

直接暴力做,并没有超时。

import java.util.Scanner;public class Main{    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        int t = sc.nextInt();        while(t-->0){            int year = sc.nextInt();            int n = sc.nextInt();            int nyear = 0;            if((year%4==0&&year%100!=0)|(year%400==0)){                nyear=1;            }//如果year是闰年,nyear就加一            while(nyear

转载地址:http://svkum.baihongyu.com/

你可能感兴趣的文章
sqlyong破解方法
查看>>
我的友情链接
查看>>
小小的起步VMware vSphere之四
查看>>
微软S2D2016滚动升级2019
查看>>
搭建中央日志服务器
查看>>
数组中第一个只出现一次的字符
查看>>
使用mian函数的命令行参数
查看>>
Bash小技巧
查看>>
数据存储
查看>>
History - BOM对象
查看>>
centos7.2下安装python3.6.2
查看>>
列表(一)
查看>>
【转】王钿《浅谈逻辑设计的学习》
查看>>
js闭包
查看>>
几何画板如何通过迭代法绘图
查看>>
BarTender表单的人性化设计—分组框
查看>>
在 CSS 中,width 和 height 指的是内容区域的宽度和高度
查看>>
河马SQLServer注入工具v1.1
查看>>
Linux基础知识随笔记
查看>>
Oracle:ORA-01791: 不是 SELECTed 表达式
查看>>