I have a solution and it fails. However I do not understand why: I just post it here:
import sys
import math
import re
n = int(input()) # Number of elements which make up the association table.
q = int(input()) # Number Q of file names to be analyzed.
atab={}
for i in range(n):
# ext: file extension
# mt: MIME type.
ext, mt = input().split()
atab[ext.upper()]=mt
print(ext + " -> " + mt, file=sys.stderr)
for i in range(q):
fname = input() # One file name per line.
print("----------------------", file=sys.stderr)
print("Filename = \"" + fname + "\"", file=sys.stderr)
m = re.match(".*\\.([a-zA-Z0-9]+)", fname)
if m:
ext = m.group(1).upper()
if len(ext) <= 10:
print("Looking for " + ext, file=sys.stderr)
if ext in atab:
print(atab[ext])
else:
print("Extension is not registered!", file=sys.stderr)
print("UNKNOWN")
else:
print("Extension is to long!", file=sys.stderr)
print("UNKNOWN")
else:
print("No extension found!", file=sys.stderr)
print("UNKNOWN")
This is the output on a failing testcase:
Standard Output Stream:
wav -> audio/x-wav
mp3 -> audio/mpeg
pdf -> application/pdf
----------------------
Filename = "a"
No extension found!
UNKNOWN
----------------------
Filename = "a.wav"
Looking for WAV
audio/x-wav
----------------------
Filename = "b.wav.tmp"
Looking for TMP
Extension is not registered!
UNKNOWN
----------------------
Filename = "test.vmp3"
Looking for VMP3
Extension is not registered!
UNKNOWN
----------------------
Filename = "pdf"
No extension found!
UNKNOWN
----------------------
Filename = ".pdf"
Looking for PDF
application/pdf
----------------------
Filename = "mp3"
No extension found!
UNKNOWN
----------------------
Filename = "report..pdf"
Looking for PDF
application/pdf
----------------------
Filename = "defaultwav"
No extension found!
UNKNOWN
----------------------
Filename = ".mp3."
Looking for MP3
audio/mpeg
----------------------
Filename = "final."
No extension found!
UNKNOWN
Failure
Found:
a
Expected:
U
I donât get it. I wrote my code in C and Iâm having trouble with the limit extension size, though I have tried limiting the extension to 10 chars or limiting the file name extension to 10 chars or not limiting anything.
It basically passes all the following tests and still stuck at 95%: 1)
2
2
htmlaaaaaaaab text/html
png image/png
index
.htmlaaaaaaaaaaaaaa 2)
2
2
htmlaaaaaa text/html
png image/png
index
.htmlaaaaaaaaaaaaaa 3)
2
2
htmlaaaaaaaab text/html
png image/png
index
.htmlaaaaaa 4)
2
2
htmlaaaaaaaa text/html
png image/png
index
.htmlaaaaaaaa
Does anyone have any other idea what to do? Or what combination to test?
Hello, nice puzzle, thanks.
Iâm wondering if itâs normal to consider â.pdfâ as a valid filename (3rd test)
I agree thatâs a valid extension but an extension cannot exist by itselfâŚit has to be after a filename (and a â.â ) since we are trying to determine MIMETYPE from a list of file.
This is not a bug, a file can not just be called .extension (before yea i know⌠but ⌠just⌠website donât know ok!). you just need to look at if the filename is correct.
What are the the factors that decide the timeout process? on an IDE it gives the correct output on the Large Dataset test case but here it gives a timeout.
It is easy to solve splitting the code onto methods but i was just curious about it.
wav audio/x-wav
mp3 audio/mpeg
pdf application/pdf
a
a.wav
b.wav.tmp
test.vmp3
pdf
.pdf
mp3
reportâŚpdf
defaultwav
.mp3.
final.
UNKNOWN
audio/x-wav
UNKNOWN
UNKNOWN
UNKNOWN
UNKNOWN
UNKNOWN
UNKNOWN
UNKNOWN
UNKNOWN
Can someone tell me plz where is a mistake in this output? For me it seems to be correct, but when checking it says:
âFailure
Found: U
Expected: aâ
(mistake on 3d test)
Hi!
I canât pass the last case Large dataset. Error message is âFailure. Process has timed out. This may mean that your solution is not optimized enough to handle some cases.â =,(((
Who can explain how to solve this case? Because the other 9 cases in puzzle I already passed.
.pdf and reportâŚpdf are valid extensions.
You can have a look at each test case by clicking on the small button on the top right of the test cases section.