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 32005 251855 122004 10000 |
Sample Output 2108190443236 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 #include2 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 >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< < 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< <
总结:循环之间的逻辑不清晰