zoukankan      html  css  js  c++  java
  • (HDOJ 1076)An Easy Task

    An Easy Task
    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
    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
     

     AC  code:

     #include<stdio.h>

    int leapyear(int Y)
    {
        
        
    if((Y%4==0 && Y%100!=0|| (Y%400==0))
          
    return 1;
        
    else
          
    return 0;
    }

    int main()
    {
        
    int Y,N,n,count;
        scanf(
    "%d",&n);
        
    while(n--)
        {
            count
    =0;
            scanf(
    "%d%d",&Y,&N);
            
    while(count<N)
            {
                
    if(leapyear(Y))
                {
                  count
    ++;
                  Y
    ++;
                }
                
    else
                {
                    Y
    ++;
                } 
            }
            printf(
    "%d\n",Y-1);
        }
        
    }
    作者:cpoint
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
  • 相关阅读:
    ##微信登陆,给大家分享一个第三方登陆
    ##Solr的各种版本下载
    ##redis在linux上的安装详解
    ##activeMq的简介与安装
    ##Springboot框架--配置文件介绍
    论面向服务架构及其应用
    MVC架构模式
    第八周总结
    细化架构阅读笔记
    第五周总结
  • 原文地址:https://www.cnblogs.com/cpoint/p/2015320.html
Copyright © 2011-2022 走看看