HDU-------An Easy Task

An Easy Task

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4088 Accepted Submission(s): 2327
 
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.
 
Author
Ignatius.L

easy task并不easy 无奈 不过不着急慢慢来 在错误和失败中学到东西才是重要的

上代码

 1 #include <iostream>
 2 using namespace std;
 3 //int leapJudge(int);
 4 int main(){
 5     int cont,sYear,pYear;
 6     
 7     cin>>cont;
 8     //while(cont--)//这个cont--还是谜一样的存在 !while(i--)中i是有个初值的,每次循环i会减1,当i的值等于0的时候,循环就会终止!
 9     
10     for(int i =0;i<cont;i++)
11     {
12         int sYear = 0;
13         int pYear = 0;
14         cin>>sYear>>pYear;
15         int leapcont = 0;  //!!!!!!重大错误就出现在这句 之前把他放在第一层循环外 也是脑子瓦特掉了 
16             int j;        
17             for(j=sYear;;j++){
18                 if(leapcont==pYear) break;
19                 if((j%4==0&&j%100!=0)|j%400==0)//去掉了判断函数 因为确实是没什么卵用
20                      leapcont++;
21             }
22         cout<<j-1<<endl;//此处也是有一个错误 应该输出j-1
23     } 
24     //system("pause");
25     return 0;
26 }
27 //int leapJudge(int Y){
28 //     if( (Y%4==0 && Y%100!=0)||Y%400==0)
29 //    return 1;
30 //}
31 
32 //#include<iostream>
33 //using namespace std;
34 //
35 //int main()
36 //{
37 //    int cases;//
38 //    int k;
39 //    cin>>cases;
40 //    while(cases--)
41 //    {
42 //        int y,n;
43 //        cin>>y>>n;
44 //        int num=0;
45 //        for(k=y;;k++)
46 //        {
47 //            if(num==n) break;
48 //            //判断是不是闰年
49 //            if(k%4==0 && k%100!=0 || k%400==0)
50 //                num++;
51 //        }
52 //        cout<<k-1<<endl;
53 //    }
54 //    system("pause");
55 //    return 0;
56 //}

总结:循环之间的逻辑不清晰

posted @ 2016-08-15 20:42  幻鼠  阅读(188)  评论(0编辑  收藏  举报