Array Counter (task 21)

Back to Problem Solutions forum

Ratzenfutz     2015-07-13 20:36:29
User avatar

Here's what I do:

  • read line 1 from stdin, split it and convert its members to uint

  • read line 2 from stdin, split it and convert its members to uint

  • create an array of size 21 (indices 0 to 20)

  • loop through line 2 array and increment the value at the respective index

  • double check: sum the members of the final array and compare with first argument of line 1

  • output result if number match, else raise exception

My results are always incorrect, although all test cases work fine.

Could anyone tell me where I might go wrong? I will provide code if necessary.

Ratzenfutz     2015-07-13 20:48:00
User avatar

I've found what's wrong. Unlike other problems this one does not accept input with commas.

TestUser     2015-07-14 07:09:41
User avatar

Hi!

I'm glad you get through it, though honestly I did not know that other problems accept input with commas - or probably I do not understand correctly what is input and how you use commas :)

Ratzenfutz     2015-07-15 20:32:25
User avatar

I use D for programming and it has a wide support range for data to be processed in any way. So if you have an array of ints A = {1, 2, 3, 4, 5, 6} I will define this as int[] A = [1, 2, 3, 4, 5, 6];. When it comes to printing I simply type A.writeln;. Output will then literally be [1, 2, 3, 4, 5, 6].

And that's where the commas come from. I guess it worked with the easiest problems.

Please login and solve 5 problems to be able to post at forum