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 1542. Autocompletion

RE2???
Posted by endtimes 14 Jan 2014 17:59
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _1542
{
    public class word
    {
        public  string line;
        public  int count;
        public  word(string g="", int f=0)
        {
            line=g;
            count =f;
        }
    }
    class sortim: IComparer<object >
    {
        public int Compare(object x, object y)
        {
            word a, b;
            a = (word)x;
            b = (word)y;
            if (a.count < b.count) return 1;
            else if (a.count > b.count) return -1;
            else return String.Compare(a.line, b.line);

        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            sortim sort = new sortim();
            int n = Convert.ToInt32(Console.ReadLine());
            word[] wor = new word[n];
            for (int i = 0; i < n; i++)
            {
                string[] temp = Console.ReadLine().Split(' ');
                wor[i] = new word(temp[0], Convert.ToInt32(temp[1]));
            }
            int g= Convert.ToInt32(Console.ReadLine());

            for (int i = 0; i < g; i++)
            {
                string request = Console.ReadLine();
                word[] select = Array.FindAll(wor, e => e.line.Substring(0,request.Length)==request );
                Array.Sort(select, sort);
                for (int i1 = 0; i1 < Math.Min(select.Length,10); i1++)
                {
                    Console.WriteLine(select[i1].line);
                }
                if (i!=g-1) Console.WriteLine();
            }
        }
    }
}