MIME Type puzzle discussion


#113

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


#114

done, thanks !! :slight_smile:


#116

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.


#117

We cant use the exceptions in python?


#118

Of course we can use them.


#119

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.


#120

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


#122

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.


#123

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


#124

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


#125

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…


#126

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


#127

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


#128

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;
         }

#129

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.


#130

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;
  }

#131

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.


#132

You can. Just use the command lines.


#133

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];

#134

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("\\.");