MIME Type puzzle discussion

Okay that’s probably my problem, I’ll try it !

done, thanks !! :slight_smile:

My tip for everyone is: whenever possible, try to use first built-in solutions before going to spend hours in implementing complicated data structures. I did this in bash and pretty much the only code needed to create the hash table was to declare the array as associative (declare -A array). Then you actually use the string keys as indices while filling it up and searching. Full code was about 30 something lines including comments, and run time for the large dataset - 1.5s.

We cant use the exceptions in python?

Of course we can use them.

So basically i use codeblocks and all the test work just fine, but when i paste the code on the website, it just tells me its wrong. You dont even show me my output so i can figure out exactly what happenes.

Can someone help me? Code is in VB.NET
This is the Result I get. I think I’m doing it all correct, but I keep getting this Error
Unknown is Printed first, but the result says it found an “A” first… Doesn’t make since

Console output
Standard Output Stream:

UNKNOWN
audio/x-wav
UNKNOWN
UNKNOWN
application/pdf
application/pdf
audio/mpeg
application/pdf
UNKNOWN
Failure

Found: a
Expected: U

Found: ‘a’ means somewhere you wrote ‘a’ (and something after or before that) while it waited ‘U’.
You can see how to do open test cases to check what went wrong below. You’ll notice that you write 3 times ‘application/pdf’ while you should to it only twice.

Looking at the lines in the expected output, you wrote ‘application/pdf’ instead of ‘UNKNOWN’, I would say you do not handle file without extensions and that name is the name of an extension.

3 Likes

Thanks for the tip. I didn’t see that menu.
I’ll be able to get it now.

Got it, Files Names need a ‘.’ somewhere… :slight_smile:

Hi there,

It seems that the large data set test encounters some issue: on the 10th line of the input file (after the mime associations, i.e. line 10011) we have :
nowIPutPointsInName.yes.pfd

In the output file, the program is waiting for answer :
application/pdf
rather than :
UNKNOWN

Is that related to the programing language? I’m quite curious nobody noticed before…

@mathieu_ponsonnet. On line 10, you have “pfd application/pdf”, so “pfd” is a valid extension which maps to “application/pdf”

My mistake then. I’ll work it out :smiley:

Language: C++
Trouble section: Large database

I’ve setup a map (EXT2) as some other people suggested, but I think I’m still accessing it the wrong (slow) way.
Any pointers on what I’m doing wrong?

 for (auto i : EXT2){
        if (i.first.c_str() == fileEXT){
             cout << i.second.c_str() << endl;  
         }
   }
  if (EXT2.find(fileEXT) == EXT2.end()){        
             cout << "UNKNOWN" << endl;
         }

Had same issue - your code probably gives ‘pdf’ value when filename is ‘pdf’ without dot. Thats why found ‘application/pdf’ instead of UNKNOWN at first occurence ‘pdf’. Check your code what exactly its doing when filename has no dots.

1 Like

I believe I solved my own problem! After thinking about it I realized theres no reason to loop through all the data each time. I just tested the extension directly and if it found it, I’d print it otherwise its UNKNOWN.

string extension = EXT2[fileEXT];
 if ( extension != ""){
        cout << EXT2[fileEXT] << endl;  
  }else{
        cout << "UNKNOWN" << endl;
  }

Files with no names, e.g. “.pdf”, “.png” should not be treated as valid, whereas tests 3 and 5 do treat them valid. You can’t create a file with no name in Windows, can you?
Neither files like “…ico” or " .ico" should be valid too.
Current test cases expect for all of the above no-name files valid MIME types, when you would naturally consider such files illegal. And whilst your code considers them illegal, you can’t pass test cases 3 and 5.
So the clarification that “.pdf”, “.png” are legal input should be added to the task description, in my opinion.

You can. Just use the command lines.

Running into a funny problem where the following lines of code lead to an arrayIndexOutOfBoundsException. It happens on line 3 here. On the first test. I’m confused on why I’m getting this problem. Thanks in advance!

        System.err.println(FNAME[i]);
        String[] temp = FNAME[i].split(".");
        String temp1 = temp[1];

An arrayIndexOutOfBoundsException means that you tried to access the element of an array at an index bigger than the one of the last element of that array (or gave a negative number).
So here, you tried to access the array ‘temp’ at index ‘1’. What if temp has only one element (thus at index 0)? Or worse, no element?

So if you’re not sure of the number of element in the array, you should check it before trying to access an element it might contains:

String temp1 = null;
if(temp.length > 1) {
    temp1 = temp[1];
}

Also, you have a problem with your split. According to the javadoc, split takes in argument a string representing a regex (regular expression). In that context, a dot is a special character meaning: any and every character. With just this java don’t know what to do and your array will always have 0 element.
If you want to split around all dot in FNAME[i], you should escape the dot in the regex:

String[] temp = FNAME[i].split("\\.");
1 Like