杭电1076 An Easy Task
2015-07-23 13:59
232 查看
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
Sample Output
//题意:找出第n个闰年是几几年
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.
//题意:找出第n个闰年是几几年
#include<stdio.h> #include<string.h> #define max 100000 int a[max+100],b[max+100],i; void fun() { int j=0; memset(a,0,sizeof(a)); for(i=1;i<=max;++i) { if((i%4==0&&i%100!=0)||i%400==0)//闰年标记 { a[i]=1; //b[++j]=i; } } } int main() { int t,y,n; fun(); scanf("%d",&t); while(t--) { scanf("%d%d",&y,&n); int num=0; for(i=y;;++i) { if(a[i])++num; if(num==n)break; } printf("%d\n",i); /* if(a[y]) { for(i=1;i<=max;++i) { if(b[i]==y) { break; } } printf("%d\n",b[i+n-1]); } else { while(!a[y])++y; for(i=1;i<=1000;++i) { if(b[i]==y) { break; } } printf("%d\n",b[i+n-1]); } */ } return 0; }
相关文章推荐
- Java实现监控多个线程状态的实现
- Hibernate 后台json封装
- 二、nginx服务器基础配置命令
- 在Oracle表数据和xml文件间相互导入导出
- 基于Ubuntu 15.04 LTS编译Android5.1.0源代码
- 设计模式-适配器模式(Adapter Pattern)
- Postfix邮件服务器搭建(五)
- Welcome to LWN.net [LWN.net]
- python的基础概念
- Using Flash Builder with Flash Professional
- java web 开发环境部署,zving框架
- Spark-1.4.0定时任务
- 奖学金文章更新 连载10第一篇 黄江桂 海口第1期学员
- 夏令营第一期【二】相识相知的我们
- ngx_queue_t双向链表
- C#高级编程五十天----栈
- CiscoWork2000使用感
- 【LeetCode 240】Search a 2D Matrix II
- 【Android杂谈】安卓手机与传感器通信
- CentOS 7 用户怎样安装 LNMP(Nginx+PHP+MySQL)