Brak wyjścia przy kompilacji przy pewnych danych wejściowych.

0

Próbuję sobie zrobić te zadanko: http://www.codeabbey.com/index/task_view/matching-words

I dla danych testowych mój program wyświetla poprawne wyjście, jednak przy próbie wykonania go z poziomu strony nie działa (nie wyrzuca nic jako output). Czy ktoś wie czemu tak się dzieje?

using System;
using System.Collections.Generic;
namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            List<string> answers = new List<string>();
            foreach(string s in input)
            {
                int index = 0;
                for (int i = 0; i != input.Length; i++)
                {
                    if(s == input[i])
                    {
                        index++;
                        if(index == 2)
                        {
                            index = 0;
                            answers.Add(input[i]);
                        }
                    }
                }
            }

            answers.Sort();
            string[] sx = answers.ToArray();
            for (int i = 0; i != sx.Length; i+=2)
            {
                try
                {
                    answers.RemoveAt(i);
                }
                catch {}
            }
            foreach (string s in answers) Console.Write(s + " ");
        }
    }
}
 
0

Nie ważne, zrobiłem. Do zamknięcia/kasacji.

using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            List<string> answers = new List<string>();
            foreach (string s in input)
            {
                int index = 0;
                for (int i = 0; i != input.Length; i++)
                {
                    if (s == input[i])
                    {
                        index++;
                        if (index == 2)
                        {
                            index = 0;
                            answers.Add(input[i]);
                        }
                    }
                }
            }

            answers.Sort();
            string[] sx = answers.ToArray();
            for (int i = 0; i != sx.Length; i += 2)
            {
                try
                {
                    answers.RemoveAt(i);
                }
                catch { }
            }
            sx = answers.ToArray();
            var clearone = sx.Distinct().ToArray();
            foreach (string s in clearone) Console.Write(s + " ");
            Console.ReadLine();
        }
    }
} 
0

Potworek ładny, a można tak:

var answers = input.GroupBy(x => x)
    .Where(g => g.Count() > 1)
    .Select(g => g.Key)
    .OrderBy(x => x); 
0

The end is signaled by the word end

1 użytkowników online, w tym zalogowanych: 0, gości: 1