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
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
  • 相关阅读:
    委托
    Math方法讲解
    正则表达式判断邮件输入的是否正确
    值类型与引用类型作为参数输出的效果
    listView 控件加上选择框
    ?: ?? ? 的区别
    学习思维导图之前先了解这些常识
    PDF文档如何添加图片签名
    CleanMyMac与腾讯柠檬清理软件的简单对比
    如何用思维导图MindManager制作一套学习法
  • 原文地址:https://www.cnblogs.com/cpoint/p/2015320.html
Copyright © 2011-2022 走看看