zoukankan      html  css  js  c++  java
  • 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);
        }
        }
    }

  • 相关阅读:
    Spring 中的邮件任务
    Spring 定时任务
    java中同步交互 与 异步交互
    Springboot 版本包冲突
    Derby 配置环境变量
    Springboot中的Web服务Tomcat改为Jetty
    二叉树中和为某一值的路径
    0-Java中this和super的用法总结
    树9:二叉搜索树的后序遍历
    位运算-输入一个整数,输出该数二进制表示中1的个数。其中负数用补码表示。
  • 原文地址:https://www.cnblogs.com/money-lady/p/3650665.html
Copyright © 2011-2022 走看看