MIME Type puzzle discussion

The stub now uses 256 instead of 50 to match the dataset

1 Like

The test is not correct in the sense that filename “.pdf” has no extension at all - in Unix-like OSes it is a dot file, a hidden one. So in the D programming language its standard library function “extension” returns that “.pdf” file has no extension but this test expected it has “.pdf” extension. It would be better if you fix this I guess.

Although in real situation you are right the statement is clear

The extension of a file is defined as the substring which follows the last occurrence, if any, of the dot character within the file name

So the test case is respecting the rules.

Well, that’s true too

Same issue with C++

std::filesystem::path(".pdf").extension();

outputs an empty string.

I understand it doesn’t align with the test/game requirements, but they really shouldn’t be punishing best practice…

best practice does not matter here. it is a puzzle.

i may be wrong, i should be right but …
you have to code your own solution. the objective in not to find the already existing function to solve it.

i screamed enough against levenshtein puzzle because it is solvable in one line in some languages when the challenge/objective should be the same for all.

5 тест валится через раз.
решение стандартное на мапе.

Так что, если у вас завалится на пятом, то пробуйте ещё и ещё…
:no_mouth:

According to Google traduction:

5 test falls through time.
The solution is standard on the map.

So if you fall on the fifth, then try again and again …

Feedback: It would be nice if it was mentioned somewhere that ALL the output will be written, and not (like in other puzzles?) be stopped at a failing line.

Error:Aborted.

at abort.c. function __GI_abort () on line 79

at Answer.cpp. function main () on line 81

Here is my Code

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

/**
 * Auto-generated code below aims at helping you parse
 * the standard input according to the problem statement.
 **/
int total=0;

struct mime 
{
    string key,value;
    int hashkey;
};

struct mime *item;
struct mime *hasharray[10000];

void insert(string key, string value)
{
    struct mime *item=(struct mime *)malloc(sizeof(struct mime));
    
    item->key=key;
    item->value=value;
    //item->hashkey=total;
    hasharray[total]=item;
   // cout << hasharray[total]->key << " " << hasharray[total]->value << endl;
    total++;
}
void search(string str)
{
    int num=0,flag=0;
    string ans;
    
    while(num<total)
    {
         if(hasharray[num]->key==str)
            {
                ans=hasharray[num]->value;
                flag=1;
                break;
            }
        else
            num++;
    }
    
    if(flag==0)
        ans="UNKNOWN";
    cout<<ans<<endl;
}        

int main()
{
    //haskey=0;
    int N; // Number of elements which make up the association table.
    cin >> N; cin.ignore();
    int Q; // Number Q of file names to be analyzed.
    cin >> Q; cin.ignore();
    for (int i = 0; i < N; i++) {
        string EXT; // file extension
        string MT; // MIME type.
        cin >> EXT >> MT; cin.ignore();
        
        insert(EXT,MT);
    }
    string str;
    
    for (int i = 0; i < Q; i++) {
        string FNAME;
        getline(cin, FNAME); // One file name per line.
        
        int k=0;
        while(FNAME[k]!='.')
            k++;
                                                                         //LINE 79
        k++;
        str=FNAME.substr(k,FNAME.length());   //LINE 81
        search(str);    
    }

}

Please explain what’s wrong and what can be done

Can anyone show me how to optimize this c#? I pass every case besides large data set. Is it possible to show all my code?

// loop through file names
            // files dictionary consists of Key = filename, value = List [0] = boolean
            // if checked already and [1] MIME Type
            // dict consists of key = extension and value = mime type
            foreach(KeyValuePair<string,List<object>> entry in files) {
                // loop through MIME types
                string ext = Path.GetExtension(entry.Key);
                ext = ext.ToLower();
                
                foreach(var key in dict.Keys)
                {
                    // do something with key
                    if(key.ToLower() == ext) {
                        entry.Value[0] = true;
                        entry.Value[1] = dict[key]; 
                    }
                }
                
                // loop through MIME types
                if((bool)entry.Value[0] == true) {
                    Console.WriteLine(entry.Value[1]);
                } else {
                    Console.WriteLine("UNKNOWN");
                }
            }

I’ve just noticed: this puzzle’s example doesn’t match the first test case. This is rather confusing, as all non-legacy I/O puzzles (who are now a majority) do match. Could this be fixed by some [CG]Rando with appropriate access rights?

1 Like

marcelpatulaccibrigadierchefmaisgardiendelapaixavanttout.jpg

Just for this reference, i put 5 stars ! :rofl:

1 Like

Continuing the discussion from MIME Type puzzle discussion:

PHP Auto generated code is wrong for this. It puts a limit of 50 characters for the test cases. It was quite annoying going through and debugging something that should work out of the box.

I did it with C++. I have been like 3 hours trying to improve the performance because of the time constraint that the large data test gives. Finally I have submitted it (even without passing the last test) and I got 100% ¿?

The Code

import ‘dart:io’;
import ‘dart:math’;

/**

  • Auto-generated code below aims at helping you parse
  • the standard input according to the problem statement.
    **/
    void main() {
    List inputs;
    int N = int.parse(stdin.readLineSync()); // Number of elements which make up the association table.
    int Q = int.parse(stdin.readLineSync()); // Number Q of file names to be analyzed.
    //the map is an dictionary of file types
    var Fmap = Map();
    for (int i = 0; i < N; i++) {
    inputs = stdin.readLineSync().split(’ ‘);
    String EXT = inputs[0]; // file extension
    String MT = inputs[1]; // MIME type.
    //this is the “dictionary”
    Fmap[EXT] = MT;
    //print();
    }
    for (int i = 0; i < Q; i++) {
    String FNAME = stdin.readLineSync(); // One file name per line.
    stderr.write(’$FNAME|’);
    var filenameparts = FNAME.split(".");
    if (filenameparts.length == 2) {
    if (filenameparts[0] == “”){print(“UNKNOWN”);}
    else if (filenameparts[1] == “”){print(“UNKNOWN”);}
    else if (!Fmap.keys.contains(filenameparts[1])) {
    print(“UNKNOWN”);
    } else {
    //the go button
    print(Fmap[filenameparts[1]]);
    }
    } else
    {
    //print(“UNKNOWN”);
    }
    }

// Write an answer using print()
// To debug: stderr.writeln(‘Debug messages…’);
//if () {}

// For each of the Q filenames, display on a line the corresponding MIME type. If there is no corresponding type, then display UNKNOWN.
//print(’$EXT’);
}

In the third test we are given a.wav which we put through our dictionary and print the result audio/x-wav and the test expects UNKNOWN. we think this is an error also Darts stderr.writeln does not seem to be working we’ve had to use stderr.write instead. I am being helped and taught how to describe a process and then write it in code, so there maybe errors that i might not know about.

I can’t find a solution for the “file size limit” test I tried everything to limit the filename size and return UNKNOWN (in C).

Same here, was quite frustrating… :angry:

Anyone can give me a tip to make my code faster ? (i am not passing the last test case).

        #include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

/**
 * Auto-generated code below aims at helping you parse
 * the standard input according to the problem statement.
 **/
int main()
{
    int N; // Number of elements which make up the association table.
    cin >> N; cin.ignore();
    int Q; // Number Q of file names to be analyzed.
    cin >> Q; cin.ignore();
    map<string,string> tableAsso;
    for (int i = 0; i < N; i++) {
        string EXT; // file extension
        string MT; // MIME type.
        cin >> EXT >> MT; cin.ignore();
        for (int i = 0; i < EXT.size();i++){
            EXT[i] = toupper(EXT[i]);
        }
        tableAsso[EXT]=MT;
    } 
    char magicalthing ('.');
    int test (0);
    for (int i = 0; i < Q; i++) {
        string FNAME;
        string monExt; // One file name per line.
        getline(cin, FNAME);

        char extension = FNAME.find_last_of(magicalthing);

        if (extension == -1){cout<<"UNKNOWN"<<endl;}
        else{
        for (int k = extension+1; k < FNAME.size(); k++){
            monExt.push_back(toupper(FNAME[k]));
        }
        if (tableAsso.count(monExt) > 0){
            cout<<tableAsso[monExt]<<endl;
        }
        else{
            cout<<"UNKNOWN"<<endl;
        }}
        }
        
}

Hello Coders,

I have quite a problem with the third test case.
My algorithm gives those extensions the following MIME type :

    pdf : UNKNOWN
    .pdf : application/pdf
    mp3 : UNKNOWN
    .mp3 : audio/mpeg

I have the following fail message :

    Found : "audio/mp..."
    Expected : "UNKNOWN"

Can anyone explain to me why “.pdf” should be associated with its corresponding MIME type while “.mp3” should not?
P.S. : Both extensions are properly mapped to the correct MIME type, no problem on that side :

    mp3 -> audio/mpeg
    pdf -> application/pdf