An Easy Task
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10133 Accepted Submission(s): 6291
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
3
2005 25
1855 12
2004 10000
Sample Output
2108
1904
43236
1 #include <iostream> 2 #include <cstdlib> 3 #include <cstdio> 4 #include <cstring> 5 6 using namespace std; 7 8 bool leap(int n) 9 { 10 if (n%400 == 0 || (n%4==0 && n%100!=0)) 11 return true; 12 else return false; 13 } 14 15 int main(void) 16 { 17 int t; 18 #ifndef ONLINE_JUDGE 19 freopen("1076.in", "r", stdin); 20 #endif 21 scanf("%d", &t); 22 while (t--) 23 { 24 int n, y; 25 scanf("%d%d", &y, &n); 26 if (leap(y)) 27 { 28 int cnt = 1, end; 29 for (int i = y+4; ; ++i) 30 { 31 if (leap(i)) 32 cnt++; 33 if (cnt == n) 34 { 35 end = i; 36 break; 37 } 38 } 39 printf("%d\n", end); 40 } 41 else 42 { 43 int cnt = 0, end; 44 for (int i = y; ; ++i) 45 { 46 if (leap(i)) 47 cnt++; 48 if (cnt == n) 49 { 50 end = i; 51 break; 52 } 53 } 54 printf("%d\n", end); 55 } 56 } 57 58 return 0; 59 }
这题不难……