描述小明出生在一个闰年他想知道什么时候可以过生日你能告诉他吗?给你一个正整数Y表示起始年份和一个正整数N你的任务是告诉小明从Y年开始第N个闰年是哪一年。注意:如果Y就是闰年那么第一个闰年就是Y。输入描述输入的第一行为一个整数T表示测试数据的组数。每一组输入包含两个正整数Y和N1=N=10000。输出描述对于每组输入输出从Y年开始第N个闰年是哪一年。希望能用c++编写代码
#include
bool isLeapYear(int year) { if (year % 4 == 0 && year % 100 != 0) { return true; } else if (year % 400 == 0) { return true; } else { return false; } }
int main() { int T; cin >> T;
while (T--) {
int Y, N;
cin >> Y >> N;
int count = 0;
int currentYear = Y;
while (count < N) {
if (isLeapYear(currentYear)) {
count++;
}
currentYear++;
}
cout << currentYear - 1 << endl;
}
return 0;
}
原文地址: http://www.cveoy.top/t/topic/jat8 著作权归作者所有。请勿转载和采集!