Hdoj 1201-18 Birthday

Source: Internet
Author: User

18-year-old birthday

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 23314 Accepted Submission (s): 7461


Problem Descriptiongardon's 18 birthday is coming, he is certainly very happy, but he suddenly thought of a question, is everyone from birth, to reach the 18 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 18 birthday.

Input is a number T, and the following T line has a date on each line, and the format is YYYY-MM-DD. As my birthday is in 1988-03-07.

Outputt lines, one number per line, indicating the number of days that the person has passed from birth to the age of 18. If this person does not have a 18 birthday, then output-1.

Sample INPUT1 1988-03-07

Sample Output65741, pay attention to judge leap Year 2, when the birthday is 02 29 o'clock to determine whether the age of 18 is a leap years if it is not a leap-year, there is no 18 birthday
#include <stdio.h> #include <string.h>int run (int x) {if (x%4==0&&x%100!=0| |    x%400==0) return 1; return 0;}    int main () {int n,j,i,s,t,l,sum;    int y,m,d;    int s1[14]={0,31,28,31,30,31,30,31,31,30,31,30,31};    int s2[14]={0,31,29,31,30,31,30,31,31,30,31,30,31};    scanf ("%d", &n);        while (n--) {scanf ("%d-%d-%d", &y,&m,&d);                if (!run (y+18)) {if (m==2&&d==29) {printf (" -1\n");            Continue        }} s=0;            for (i=y;i<y+18;i++) {if (run (i)) s+=366;        else s+=365;            } if (run (y+18)) {//s+=366;            for (i=1;i<m;i++) {s+=s2[i];        } S+=d;            } else {//s+=365;            for (i=1;i<m;i++) {s+=s1[i];        } S+=d;     } sum=0;   if (run (y)) {for (i=1;i<m;i++) {sum+=s2[i];        } Sum+=d;            } else {for (i=1;i<m;i++) {sum+=s1[i];        } Sum+=d;    } printf ("%d\n", s-sum); } return 0;}

Hdoj 1201-18 Birthday

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.