hdu 1076(An Easy Task)
来源:互联网 发布:淘宝视频直播内容下载 编辑:程序博客网 时间:2024/06/15 14:51
An Easy Task(原网址:http://acm.hdu.edu.cn/showproblem.php?pid=1076)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 17263 Accepted Submission(s): 11014
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.
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).
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
32005 251855 122004 10000
Sample Output
2108190443236
题意:
给你一个数字t,随后的n行每行都有两个数字y和n,y为一个年份,求y年(包括)后的第n个闰年。(n组数据)
参考代码:
#include<iostream>using namespace std;int main(){ int x,y,n,i,s; cin>>n; for(i=0;i<n;i++) { cin>>x>>y; s=0;//计数器清零 while(s<y)//当找到的闰年的个数等于数据所给的闰年个数时退出循环 { if(x%4==0 && x%100!=0)//判断是否是闰年① s++;//是闰年计数+1 else if(x%400==0)//判断是否是闰年② s++;//是闰年计数+1 x++;//当前年份后移一年 } cout<<x-1<<endl; } return 0;}
运行结果:
Accepted107615MS1956K552 B题解:
易错点1:清零。计数器一定要清零,否则就会一直加下去!!!
易错点2:闰年判断。判断规则:四年一闰,百年不闰,四百年又闰。所以当它是4的倍数而不是100的倍数①时判断为闰年,当它是400的倍数②时也是闰年。
易错点3:x-1。最后输出时一定要-1,因为在找到目标数后退出循环前x++依然执行了,要把这次加的抵消掉。
参考知识:
无。
0 0
- HDU 1076 An Easy Task (水)
- hdu 1076 An Easy Task (水题)
- hdu 1076(An Easy Task)
- HDU 1076 An Easy Task(水~)
- hdu 1076 An Easy Task
- HDU 1076 An Easy Task
- HDU 1076 An Easy Task
- Hdu 1076 - An Easy Task
- HDU 1076 An Easy Task
- hdu 1076 An Easy Task
- hdu 1076 An Easy Task
- HDU 1076 An Easy Task
- hdu-1076-An Easy Task
- hdu 1076 An Easy Task
- HDU 1076An Easy Task
- hdu 1076 An Easy Task
- hdu 1076 An Easy Task
- HDU 1076 An Easy Task
- Decorator——结构型模式
- G - Give Me the Number --- (first qualifying)
- 再谈循环嵌套
- PopupWindow点击外部区域消失(三)
- ssh 反向代理
- hdu 1076(An Easy Task)
- 心中的激动与兴奋交加,阿里内推面试
- UITableViewRowAction的使用
- 比较炫丽的幻灯片
- FastJson和Gson解析json的小例子
- 深度学习-CNN入门
- Maven核心概念之依赖,聚合与继承
- AJAX的工作原理
- HDU 1150 Machine Schedule(最小点覆盖)