• HDU 1076 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
    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.
     
    题意:先输入一个整数,表示测试的数据的组数,每一组包括两个整数,分别表示起始年份、起始年份后第几个闰年。
    分析:判断出第一个闰年之后不用再将年份逐渐加1,逐渐加4简单一些。
    AC源代码(C语言):
     1 #include<stdio.h>
     2 int main()
     3 {
     4   int a,b,n,i,j;
     5   scanf("%d",&n);
     6   while(n--)
     7   {
     8     i=j=0;
     9     scanf("%d%d",&a,&b);
    10     do
    11     {
    12       if((a%4==0&&a%100!=0)||a%400==0)
    13         {
    14           i++;
    15           a+=4;                                                               
    16         }                    
    17       else  a++;                  
    18                         
    19     } while(i!=b);       
    20    printf("%d\n",a-4);                   
    21   }        
    22  return 023 }

    2013-01-24

  • 相关阅读:
    java反射机制
    Java注解的使用
    C3P0数据库Jar包的使用
    异常处理
    集合的概念
    程序员必备之二分查找
    ArrayList的使用
    HashMap的使用
    Final的使用
    类的基本结构
  • 原文地址:https://www.cnblogs.com/fjutacm/p/2875757.html
Copyright © 2020-2023  润新知