• An Easy Task


    An Easy Task

    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
    Total Submission(s) : 1   Accepted Submission(s) : 1

    Font: Times New Roman | Verdana | Georgia

    Font Size:

    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.

    题意:
    给出起始年份Y,让你求第N个闰年的具体年份。
    注意:We call year Y a leap year only if (Y%4==0 && Y%100!=0) or Y%400==0.
            并不是每4年,一闰年,若成立即:Y%4==0 即可。但要满足这个(Y%4==0 && Y%100!=0)。
    代码:
    #include<stdio.h>
    int main(){
        int T,n,y;
        int i,count;
        while(scanf("%d",&T)!=EOF){
        while(T--){
            count=0;
            scanf("%d%d",&y,&n);
            for(i=y;count<n;i++)/* 闰年不是隔四年一循环*/            
                if((i%4==0&&i%100!=0)||(i%400==0))
                    count++;/*是闰年就++,等到到了第nth时候就停止,i-1就是要求的年份*/
            printf("%d ",i-1);
        }
        }
    }

  • 相关阅读:
    ios属性或者变量的前缀-杂记
    xcode注释方法
    ios 不同的数据类型转化为json类型
    第一部分----HTML的基本结构与基本标签
    Git使用总结
    c#后台弹出框
    svn下载安装
    svn配置
    access 日期转换
    C# 中关于汉字与16进制转换的代码
  • 原文地址:https://www.cnblogs.com/money-lady/p/3650665.html
Copyright © 2020-2023  润新知