HDU-------An Easy Task

时间:2023-03-09 08:38:14
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 无奈 不过不着急慢慢来 在错误和失败中学到东西才是重要的

上代码

 #include <iostream>
using namespace std;
//int leapJudge(int);
int main(){
int cont,sYear,pYear; cin>>cont;
//while(cont--)//这个cont--还是谜一样的存在 !while(i--)中i是有个初值的,每次循环i会减1,当i的值等于0的时候,循环就会终止! for(int i =;i<cont;i++)
{
int sYear = ;
int pYear = ;
cin>>sYear>>pYear;
int leapcont = ; //!!!!!!重大错误就出现在这句 之前把他放在第一层循环外 也是脑子瓦特掉了
int j;
for(j=sYear;;j++){
if(leapcont==pYear) break;
if((j%==&&j%!=)|j%==)//去掉了判断函数 因为确实是没什么卵用
leapcont++;
}
cout<<j-<<endl;//此处也是有一个错误 应该输出j-1
}
//system("pause");
return ;
}
//int leapJudge(int Y){
// if( (Y%4==0 && Y%100!=0)||Y%400==0)
// return 1;
//} //#include<iostream>
//using namespace std;
//
//int main()
//{
// int cases;//
// int k;
// cin>>cases;
// while(cases--)
// {
// int y,n;
// cin>>y>>n;
// int num=0;
// for(k=y;;k++)
// {
// if(num==n) break;
// //判断是不是闰年
// if(k%4==0 && k%100!=0 || k%400==0)
// num++;
// }
// cout<<k-1<<endl;
// }
// system("pause");
// return 0;
//}

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