MIME Type puzzle discussion


#322

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


#323

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.


#324

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.


#325

Well, that’s true too


#326

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…


#327

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.


#328

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

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


#329

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 …


#330

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.


#331

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


#332

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

#333

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?


#334

marcelpatulaccibrigadierchefmaisgardiendelapaixavanttout.jpg

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