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
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
  • 相关阅读:
    hudson中 ANT 编译警告: 编码 UTF-8 的不可映射字符解决方法
    Jmeter与hudson,ant集成
    Hudson配置路径
    python 面向对象:封装---对象的属性可以是另一个类创建的对象
    python 面向对象:封装
    python3 f-string格式化字符串的高级用法
    iOS微信支付无法直接返回APP的问题
    学习git&github
    Appium之xpath定位详解
    selenium等待方式详解
  • 原文地址:https://www.cnblogs.com/cpoint/p/2015320.html
Copyright © 2011-2022 走看看