Find Dates

View as PDF

Submit solution

Points: 7
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type

I have a document full of dates that you need to process. I am really busy, so I need you to write a program for me to find all the dates. I only want valid dates, that is dates that actually exist, in the format YYYY-MM-DD exactly. Any date that does not fit exactly in YYYY-MM-DD or does not actually exist must be ignored. A valid date will also have non-alphanumeric characters on both sides.

Note: Leap years are very important for me.

Input Specification

The first line is an integer N, the number of lines in the input. The next N lines will be the document you need to process.

Output Specification

You are to output all valid dates in the exact format YYYY-MM-DD inside the document.

Sample Input

4
Archduke Franz Ferdinand was killed on 1914-06-28. On 1914-07-28,
Austria-Hungary declared war on Serbia. Germany attacked Luxemburg on 08-02,
and war was declared on France on 1914-08-03. On 04-08-1914, Britain declared
war.

Sample Output

1914-06-28
1914-07-28
1914-08-03

Comments


  • 1
    faraz123  commented on Sept. 5, 2020, 7:47 p.m.

    My output matches the sample output exactly (for TC 1). Is TC1 different than the sample?


    • 2
      Kirito  commented on Sept. 5, 2020, 8:01 p.m.
      1. Yes, the test case is different from the sample (you can verify this by submitting the sample output in Text.)
      2. Your logic for handling leap years is wrong.

  • 0
    omaewamoushindeiru  commented on June 9, 2015, 2:11 a.m.

    Does the order in which the dates are outputted matter?


    • 0
      Xyene  commented on June 9, 2015, 4:01 a.m.

      Yes.


  • 13
    bobhob314  commented on Jan. 31, 2015, 12:11 a.m.

    I had to use this for reference.

    ;(


  • 1
    Walt28  commented on Dec. 8, 2014, 3:03 a.m.

    The judge reports wrong answer back to me, but the output looks correct. Any tips on how to solve?


    • 0
      omaewamoushindeiru  commented on Dec. 8, 2014, 4:15 p.m.

      Same issue here..


      • 0
        quantum  commented on Dec. 9, 2014, 4:28 a.m.

        Read the problem statement more carefully, as there's something you're missing.


        • 0
          omaewamoushindeiru  commented on Dec. 11, 2014, 5:46 a.m.

          I see it now, it's the format of output


          • -1
            Walt28  commented on Dec. 13, 2014, 5:38 p.m.

            Could you elaborate on that please?


            • 0
              Xyene  commented on Dec. 13, 2014, 5:56 p.m.

              Carefully re-read the second sentence of the problem statement. There's something you're missing.


  • -2
    omaewamoushindeiru  commented on Dec. 7, 2014, 7:21 p.m.

    Weird, it gives the right output and doesn't crash on my computer. But the judge says it gets out of bounds exception?


    • 0
      FatalEagle  commented on Dec. 7, 2014, 8:22 p.m.

      Make your own corner cases to run your solution on.


  • 13
    quantum  commented on Sept. 28, 2014, 1:45 a.m. edit 2


    • 2
      PaulOlteanu  commented on Dec. 8, 2014, 11:29 p.m.

      I like how you support the alt-text without having to click through to the comic.