ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1002. Phone Numbers

Why is my answer wrong??
Posted by Rosandra 19 Nov 2009 18:20
What is wrong with this code... it does exactly what the description says and I can't find my error. Could somebody take a look and help me a bit?

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

namespace _1002.Phone_numbers
{
    class Program
    {
        static void Main(string[] args)
        {
            List<char>[] dictionary = new List<char>[10];

            (dictionary[0] = new List<char>()).AddRange(new char[] { 'o', 'q', 'z' });
            (dictionary[1] = new List<char>()).AddRange(new char[] { 'i', 'j' });
            (dictionary[2] = new List<char>()).AddRange(new char[] { 'a', 'b', 'c' });
            (dictionary[3] = new List<char>()).AddRange(new char[] { 'd', 'e', 'f' });
            (dictionary[4] = new List<char>()).AddRange(new char[] { 'g', 'h' });
            (dictionary[5] = new List<char>()).AddRange(new char[] { 'k', 'l' });
            (dictionary[6] = new List<char>()).AddRange(new char[] { 'm', 'n' });
            (dictionary[7] = new List<char>()).AddRange(new char[] { 'p', 'r', 's' });
            (dictionary[8] = new List<char>()).AddRange(new char[] { 't', 'u', 'v' });
            (dictionary[9] = new List<char>()).AddRange(new char[] { 'w', 'x', 'y' });

            List<String> inputs = new List<string>();

            int c = -1;
            do
            {
                inputs.Add(Console.ReadLine());
                c++;
            } while (inputs[c] != "-1");

            bool procede = true;

            while (procede)
            {
                String number = inputs[0];
                List<String> words = inputs.GetRange(2, Int32.Parse(inputs[1]));
                inputs.RemoveRange(0, Int32.Parse(inputs[1]) + 2);

                if (inputs[0] == "-1") procede = false;

                String output = String.Empty;

                while (words.Count > 0)
                {
                    StringBuilder outputs = new StringBuilder();
                    for (int i = 0; i < number.Length; i++)
                    {
                        if (i == 1 && output == String.Empty)
                        {
                            words.Clear();
                            break;
                        }

                        foreach (String word in words)
                        {
                            bool check = false;

                            if (dictionary[Int32.Parse(number[i].ToString())].Contains(word[0]))
                            {
                                for (int j = 1, k = i + 1; j < word.Length && k < number.Length; j++, k++)
                                {
                                    if (dictionary[Int32.Parse(number[k].ToString())].Contains(word[j]) == false)
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        check = true;
                                    }
                                }

                                if (check)
                                {
                                    outputs.Append(word + " ");
                                    i += word.Length - 1;
                                    words.Remove(word);
                                    break;
                                }
                            }
                        }
                    }

                    if (output == String.Empty)
                    {
                        output = outputs.ToString().TrimEnd();
                    }
                    else
                    {
                        if (outputs.ToString().TrimEnd().Split(' ').Length < output.Split(' ').Length)
                        {
                            output = outputs.ToString().TrimEnd();
                        }
                    }
                }

                if (output == String.Empty)
                {
                    Console.WriteLine("No solution.");
                }
                else
                {
                    Console.WriteLine(output);
                }
            }
        }
    }
}