/* 算闰年,思路简单,按照题目的要求就行了 判断闰年的条件 ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) */ # include <stdio.h> int judge_leap(int year) { if(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) return 1; return 0; } int main(void) { int T; scanf("%d", &T); getchar(); //吸收回车符。 while(T--) { int year,N; scanf("%d %d", &year, &N); while(N) { int temp = judge_leap(year); if(temp == 1) N--; if(N == 0) //当N=0时,此时已经算到了第N个闰年了,不能year++ break; year++; } printf("%d\n", year); } return 0; }
原文地址:http://blog.csdn.net/xu758142858/article/details/44113837