18-year-old birthdayTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 21864 Accepted Submission (s): 6933
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 Input
11988-03-07
Sample Output
6574
Authorgardon
Sourcegardon-dygg Contest 2
recommendjgshining | We have carefully selected several similar problems for you:1205 1106 1215 1228 1234
When the red accpted appeared in front of me, I almost burst into tears, really, even today is April Fool's Day, but this is my truth .... Even if it's a big fruit, Mama egg! I've been a full a for 1 hours, one hours ... Everyone a friend, AC and not easy, and the line and cherish ah. According to the general idea of C + +, this problem is to use the format input scanf ("%d-%d-%d", Year,month,day), and then again with a leap year common year to engage in, and then consider no 18 birthday this case, is if (month==2& &day==29) {printf ("-1"); Continue}. I started to think so, but decided to seriously learn Java, I want to use Java to AC this big fruit, and then just formatted input month and day, it makes no, but one thing I found, is the Java package Calendar class is really useful, I just need to call directly on it, but because I'm not familiar with the usage, I've gone a lot of detours and wasted a lot of time ... But in short I think my method is more innovative, leap year common year what, I do not need tube!
Import java.io.*;import java.text.parseexception;import java.text.simpledateformat;import java.util.*;p ublic class Main{public static void Main (string[] args) {Scanner input = new Scanner (system.in); int n = input.nextint (); Number t,t rows have a date input.nextline (); for (int i = 0; i < n; i++) {String time = Input.nextline (); The read-in date is saved in the string time variable SimpleDateFormat sdf = new SimpleDateFormat ("Yyyy-mm-dd"); if (n = = 0) break;try{date date1 = Sdf.parse (time); Time is converted to date type Date Date2 = new Date (); Initialize Date2 to save 18 years after the date Calendar Cal1 = Calendar.getinstance (); Initialize CAL1 to save the initial date of Calendar Cal2 = Calendar.getinstance (); Initialization cal2 is used to save 18 years after date cal1.settime (date1); Cal2.settime (date1); Cal2.add (Calendar.year, 18); Plus 18 years after the Cal2date2 = Cal2.gettime (); Long day1 = (long) date1.gettime ()/(1000 * 60 * 60 * 24); Total number of days to calculate the initial date long day2 = (long) daTe2.gettime ()/(1000 * 60 * 60 * 24); Count the total number of days after 18 years if (Cal1.get (calendar.month) + 1 = = 2//calendar.month month is starting from 0, so add 1&& cal1.get (calendar.date) = =//calendar.date is the day {System.out.println ("1");} else{system.out.println (Day2-day1);// Subtraction is the past days! }}catch (ParseException e) {System.out.println ("Input failed! "); E.printstacktrace ();}}}
hdu-1201-18 Birthday (Java AC uses calendar class)