what do you do then??
To me, as a beginner in C#, this puzzle is very hard and complex.
I cannot even solve the second test.
I donât understand why my defined array with stored values cannot be reversed.
Is there even needed array reversing?
Definitely not easy puzzle for me.
Is there super easy ones?
There is a bug in COC C#, because Test2 fails even on outputting âUNKNOWNâ with Console.WriteLine().
Standard Output Stream shows UNKNOWN, but no matter what:
Found: Nothing
Expected: UNKNOWN
my code below:
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
class Solution
{
static void Main(string[] args)
{
int N = int.Parse(Console.ReadLine()); // Number of elements which make up the association table.
int Q = int.Parse(Console.ReadLine()); // Number Q of file names to be analyzed.
string[] arr = new string[N];
for (int i = 0; i < N; i++)
{
string[] inputs = Console.ReadLine().Split(' ');
string EXT = inputs[0]; // file extension
string MT = inputs[1]; // MIME type.
arr[arr.GetLength(0)-i-1] = MT;
}
for (int i = 0; i < Q; i++)
{
string FNAME = Console.ReadLine(); // One file name per line.
}
bool found = false;
foreach(var item in arr)
{
if(item.Contains("gif") || item.Contains("png") || item.Contains("html"))
{
Console.WriteLine($"{item}");
found = true;
}
else
{
found = false;
}
}
if(!found)
{
Console.WriteLine("UNKNOWN");
}
}
}
Thereâs a bug in your code. Youâre reading file names and then disregarding them right away.
If this puzzle proves too difficult for you, you may want to learn and brush up your C# knowledge using other websites first. CodinGame is intended for those with basic knowledge in a programming language.
You are right about having bug in my code.
The bug I found in âelseâ statement where I missed adding output Console.WriteLine(âUNKNOWNâ).
Not sure if bug accounts not in disregarding file names. I havenât made there yet.
But thanks anyway for mentioning!
Youâre welcome.
If you have further questions regarding your code, you may share it with me via private message. Itâs better not to post codes in public in this forum.
Ok, got it!
ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
add this to the beginning of the main function)
Hi, I think there is something broken in the tests at least for c++.
My old c++ solution that already passed two years ago, times out in the last ide validator.
I tried several (valid) c++ solutions from other users here and they also time out.
In fact, I couldnât find a single c++ solution that was published on codingame for this puzzle that passed in the ide.
The Java version of my program (which is identical in every aspect) passes all tests.
Replying because i have a similar problem. I canât pass the last test case for large datasets because my code âdoesnât limit extensionsâ. I am pretty sure it does. Does anyone else have a similar problem ?
How do you know that is the reason? Where does that quote âdoesnât limit file extensionsâ come from? The console?
Also, what programming language are you using?
Apologies. i was way to vague and should have been more specific. I used C++. I couldnât pass test case 5 and the console gave the error message:
âFailure
Process has timed out. This may mean that your solution is not optimized enough to handle some cases.â
After i submitted my solution anyway it passed 9 out of 10 validators. The one that it didnât pass is number 8 : Limit size in extensions
No worries. Now that I understand your situation, there are two things I can do:
-
Test 5: Very likely thereâs an issue with that test case, which was also reported by @Ultrixx last month. Iâll raise a bug report on Discord within this week to ask CodinGame staff to look into it.
-
Validator 8: Although my old C++ code now times out on Test 5, the same code is still able to pass all validators. That probably indicates either a bug in your code or your code being too slow. If you want, you may send me your code in private message and Iâll take a look at it tomorrow.
EDIT
Iâve searched this forum topic just now. It appears that the issue isnât new as players raised it a few years ago. CodinGame staff mentioned that they had fixed the C/C++ timeout issue (see here, here and here). A player mentioned one way and another player mentioned another way which helped them pass Test 5. So it might actually be doable.
@BlaiseEbuth If itâs ok for you, could you please help test and confirm whether your implementation still passes all the tests and validators? (Iâm trying myself but havenât succeeded so far.) If it doesnât, I might later on ask CG to take a look. Or I might ask anyway if the level of optimisation is too much to ask for, given that the puzzle is classified as Easy.
Thank you.
Hey!
It seems I donât have kept the djb2 code. But I can confirm that my C++ code using std::map doesnât pass the 5th testcase anymore, even with optimization pragmas, but passes all the validators.
Also, no problems with solutions in other languages like Perl. Even my Clojure solution passes itâŚ
The C++ environment is probably less optimized for std now than it used to beâŚ
I could retry to implement a hashmap, but even if it works, it makes the puzzle out of the easy category in C++, as it was already the case for C. Though itâs still pretty easy in other languages, so IDKâŚ
Thank you for your reply!
Itâs good to know weâre on the same page about the challenge this poses in C++ and even C. Iâll give it some more thought before reaching out to CG about the issue. Thanks again!
I did some tests with C++ and found that printing consumes the majority of time.
I wrote a solution which, instead of cout
ing a line per loop iteration, outputs to an in-memory buffer first and then dumps everything to stdout at the end. No micro-optimizations, like avoiding allocations, were applied. This solution took just 30ms to do everything except printing, which is way below the time limit of 500ms (obtained experimentally). My solution is available in case anyone is interested.
And your code still times out in the last test, because of the printing, right?
Yes. Only a part of the output was printed before timing out.