Nyoj 312 && HDU 1201 Birthdays (date calculated)

Source: Internet
Author: User

Link: click here

Test instructions

description
The 20-year-old birthday is coming, he is certainly very happy, but he suddenly thought of a question, is everyone from birth, to reach the 20 birthday when the number of days are the same? It doesn't seem to be all that, so he wants to ask you to calculate the total number of days he and his friends have passed since they were born to their 20 birthday.
input
a number T, followed by the T line, each line has a date, the format is YYYY-MM-DD. As my birthday is in 1988-03-07.
output
t rows, per A number that indicates the number of days that the person has passed from birth to the age of 20. If this person does not have a 20 birthday, then output-1.
11988-03-07  
example output
7305  

Ideas:
<1> the number of days that the year of birth combined with the number of days spent on the 20 birthday is counted as one year.
<2> does not consider a leap year, 20*365 days are spent 20 years.
<3> consider alone, if the year of birth is a leap years, and born before February 29, must go through February 29, the total number of days plus 1, for 20 years of age, if the year is a leap years, and after February 28 born also must go through February 29 this day, so the total number of days plus 1.
<4> other years as long as a leap year, the total number of days plus 1 days.
<5> Special Cases

Code:

#include <math.h> #include <queue> #include <deque> #include <vector> #include <stack># Include <stdio.h> #include <ctype.h> #include <string.h> #include <stdlib.h> #include < Iostream> #include <algorithm>using namespace std; #define MAX (b) A>b?a:b#define Min (A, b) a>b?b:a#  Define MEM (A, B) memset (A,b,sizeof (a)) int dir[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};const double EPS = 1e-6;const double Pi =    ACOs ( -1.0); static const int inf= ~0u>>2;static const int MAXN =110;int h[100],w[100],map[200];int isleap (int yy) { if ((yy%4==0&&yy%100!=0) | | |    yy%400==0) return 1; return 0;}    int main () {int n,m,i,j;    cin>>n;        while (n--) {int yy,mm,dd;        int data=20*365;        scanf ("%d-%d-%d", &AMP;YY,&AMP;MM,&AMP;DD);            if (!isleap (yy+20) &&mm==2&&dd==29) {puts ("-1");        Continue } if (Isleap (yy) && (mm<2| |    (mm==2&&dd<=28))) Data++; if (Isleap (yy+20) && (mm>2| | (mm==2&&dd==29)))        data++;        for (int i=yy+1; i<=yy+19; i++) {if (Isleap (i)) data++;    } printf ("%d\n", data); } return 0;}


Nyoj 312 && HDU 1201 Birthdays (date calculated)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.