C# – Basic Exam – Fruit Market

On the 14.04.2014 I have applied for the SoftUni – a Software University in Sofia, Bulgaria. There were 5 C# problems and I managed to resolve completely 3 of them, thus gaining 300 points and being ranked in 278 place out of 1200 applicants. To be honest, I could have opted for more, but I was a little tired already and I was sure that the result will grant me a place as a distance student. Furthermore, the last two problems were with binary calculation and char conversion, which were not exactly my favourite ones.

SoftUni

So, back to the point – in this article I will present the first problem, my solution and the original solution. The problem is a little easy to understand and to code, but it still needed some extra attention to some of the details. The original problem is explained here.

As you probably see, there are just two tricky moments, which you should take care of, in order to pass the 16 automated tests successfully – the output number should be in the format “0.00” and one should be careful about the cases and the if-operators. Anyway, I have spent about an hour on this and at the end I came up with something really terrible – 655 lines of code! Really, something worthy for going to www.govnokod.ru, but as far as I had 100 points I have decided to go further.

Here is my “outstanding” result:

And if you are interesting – here is the original solution from the author of the problem – 61 lines of understandable code… :

Anyway, in the other two problems, I had better code 🙂

Posted in C Sharp Tricks Tagged with: , ,