zoukankan      html  css  js  c++  java
  • 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
    View Code
     1 #include<iostream>
     2 #include<stdio.h>
     3 using namespace std;
     4 bool judge(int n) {
     5  return (n%4==0&&n%100!=0||n%400==0);
     6 }
     7 int Y,n;
     8 int main() {
     9  int T;
    10  scanf("%d",&T);
    11  while(T--) {
    12   scanf("%d%d",&Y,&n);
    13   while(n) {
    14    if(judge(Y)) {
    15     n--;
    16     if(n!=0) 
    17     Y+=4;
    18    }
    19    else
    20    Y+=1;
    21   }
    22   printf("%d\n",Y);
    23  }
    24   return 0;
    25 }
  • 相关阅读:
    mysql-数据库增删改查
    判断,循环
    数组
    html 三种垂直居中
    箭头函数
    Array类型
    object
    JAVA WEB 行业技术
    一个好的程序员
    经典语录
  • 原文地址:https://www.cnblogs.com/xiaxiaosheng/p/3073777.html
Copyright © 2011-2022 走看看