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
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
  • 相关阅读:
    09 shell脚本程序练习
    springboot整合vue03-创建springboot工程
    springboot整合vue02-创建前端页面
    springboot整合vue01-创建vue工程
    pe工具04-获取数据目录
    pe工具03-获取节表信息
    pe工具02-解析pe头信息
    pe工具01-获取进程和模块
    以挂起方式创建进程
    进程
  • 原文地址:https://www.cnblogs.com/cpoint/p/2015320.html
Copyright © 2011-2022 走看看