HDOJ 1076 An Easy Task(闰年计算)
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<n){//当nyear小于n时,就循环
year++;
if((year%4==0&&year%100!=0)|(year%400==0)){
nyear++;
}//year是闰年,nyear就加加
}
System.out.println(year);
}
}
}
HDOJ 1076 An Easy Task(闰年计算)的更多相关文章
- 【HDOJ】1076 An Easy Task
水题,如题. #include <stdio.h> #define chk(Y) (Y%4==0 && Y%100!=0) || Y%400==0 int main() { ...
- HDU 1076 An Easy Task
题解:枚举即可…… #include <cstdio> int main(){ int now,y,n,T,count; scanf("%d",&T); whi ...
- An Easy Task
An Easy Task Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- HDU-------An Easy Task
An Easy Task Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- HDU-1076-An Easy Task(Debian下水题測试.....)
An Easy Task Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- CodeForces462 A. Appleman and Easy Task
A. Appleman and Easy Task time limit per test 1 second memory limit per test 256 megabytes input sta ...
- ZOJ 2969 Easy Task
E - Easy Task Description Calculating the derivation of a polynomial is an easy task. Given a functi ...
- An Easy Task(简箪题)
B. An Easy Task Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO f ...
- Codeforces 263A. Appleman and Easy Task
A. Appleman and Easy Task time limit per test 1 second memory limit per test 256 megabytes input ...
随机推荐
- 数据迁移sql
1.把数据库test中的表Table1中的数据插入到数据库test2中的表Table2:insert into test2.Table2(a,c,d) select a,c,5 from test.T ...
- redis 本机链接服务端命令
在windows 本机链接服务端redis,需要下载windows 端的redis: 1,运行redis-server.exe程序:2,打开cmd 控制台3,执行命令 D:\redis64\redis ...
- Android Configuration change引发的问题及解决方法
之前在学习Fragment和总结Android异步操作的时候会在很多blog中看到对Configuration Change的讨论,以前做的项目都是固定竖屏的,所以对横竖屏切换以及横竖屏切换对程序有什 ...
- ANDROID内存优化(大汇总——中)
转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 写在最前: 本文的思路主要借鉴了2014年AnDevCon开发者大会的一个演讲PPT,加上 ...
- JAVA虚拟机与内存
资料整理自网络(侵删) JVM内存 组成 JAVA的JVM的内存可分为3个区:堆(heap).栈(stack)和方法区(method) 栈区: 1.每个线程包含一个栈区,栈中只保存基础数据类型的对象和 ...
- mwc config.h 中文注释
#ifndef CONFIG_H_ #define CONFIG_H_ /*************************************************************** ...
- XML数据的读取—数据库配置文件
数据库配置文件(config.xml) <?xml version="1.0" encoding="utf-8"?> <configurati ...
- struts2获取request、session、application
struts2获取request.session.application public class LoginAction extends ActionSupport implements Reque ...
- css样式之边框和内外边距
1.css样式之边框:border 实心的边框: <!DOCTYPE html><html> <head> <meta http-equiv="co ...
- C++标准库<string>简单总结
C++标准库<string>简单总结 在C++中,如果需要对字符串进行处理,那么它自带的标准库<string>无疑是最好的选择,它实现了很多常用的字符处理函数. 要想使用标准C ...