1 Replies - 1351 Views - Last Post: 13 February 2016 - 02:27 PM Rate Topic: -----

#1 icon mad deer   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 24-June 15

What's wrong with my code? What does the fox say?

Posted 13 February 2016 - 02:17 PM

Hey guys,

I just can't find what's wrong in my code. The problem I am trying to solve is this:
https://open.kattis....atdoesthefoxsay
It's a website where you can upload your solutions to problems, which is then compiled and executed in a number of test cases. It doesn't say what's wrong, just that I get the wrong answer, but when I run it (after replacing Console.ReadLine() with test values corresponding to what they have on their website) on my local machine, I do get the correct output. Please help, I can't sleep because I feel so stupid. It should be an easy problem to solve, shouldn't it?

My code looks like this:

using System;
using System.Collections.Generic;
using System.Text;

namespace WhatDoesTheFoxSay
{

    class Program
    {
        static int Main(string[] args)
        {
            int numTestCases = 0;
            string preGatheredInfo = "";
            string[] preGatheredInfoSplitted;

            List<string> recordedSounds;
            List<string> knownAnimalSounds = new List<string>();

            numTestCases = Int32.Parse(Console.ReadLine());

            /* Outer for-loop for each test case */
            for (int i = 0; i < numTestCases; i++)
            {
                recordedSounds = new List<string>(Console.ReadLine().Split(' '));

                /* Store sounds for all known animals */
                while (preGatheredInfo != "what does the fox say?")
                {
                    preGatheredInfo = Console.ReadLine();
                    if (preGatheredInfo != "what does the fox say?")
                        break;
                    preGatheredInfoSplitted = preGatheredInfo.Split(' ');
                    knownAnimalSounds.Add(preGatheredInfoSplitted[2]);
                }

                /* ... For each known sound that an animal makes ... */
                foreach (string knownAnimalSound in knownAnimalSounds)
                {
                    /* ... just remove it from the list of recorded sounds. The rest belongs to the fox! */
                    recordedSounds.RemoveAll(x => x == knownAnimalSound);
                }


                /* Print out whats left in the recorded sound list. This will be the answer to the question: "what does the fox say?" */
                Console.WriteLine("{0}", string.Join(" ", recordedSounds.ToArray()));

                preGatheredInfo = "";
                preGatheredInfoSplitted = null;
                recordedSounds.Clear();
                knownAnimalSounds.Clear();

            } /* End of test-case */

            return 0;
        }
    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: What's wrong with my code? What does the fox say?

#2 icon mad deer   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 24-June 15

Re: What's wrong with my code? What does the fox say?

Posted 13 February 2016 - 02:27 PM

I just realized that I wrote a fault condition just before posting this thread. I changed it a bit before posting, but it's unlikely to change the output unless there is an animal that has the sound "the" (from "what does the fox say?")... Anyway.. I meant to break when preGatheredInfo == "what does the fox say?".
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1