C# – Taking only numbers from array and working with them – (The Horror)

Looking into some programming task is sometimes challenging. You may think that the answer is quite simple, but actually someone has decided to make you sweat. In this task  you should read one line from the console and print the sum and the count of all even positions. Quite trivial… Or so I thought.

After spending some 5 minutes (literally 5) I was able to come up with a solution, which was rather dissatisfying:

Printer

My solution worked only at 60% of the tests. At first I thought that I am missing something, so I spent some minutes more, looking into the task. I tried with Big Integers, but the result was the same. Finally I assumed, that if the first given digit is “0”, I miss it, when I convert to int. So, I tried and I have received 70 points. Still, not good. After thinking about another 20 minutes, I finally decided to take a look at the tests, which are give run-time error. And these tests had letters in them… So, I could not use my code and I had to re-write it (in the initial code I have assumed that we get only integers, so the cast to integer was breaking it). Finally this is what I get:

Not as quick and not as neat as I wanted, but it still works!

About

VBA Developer

Tagged with: , , , ,