Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.InteropServices;
- namespace Test
- {
- class Program
- {
- private static void Main(string[] args)
- {
- int count = int.Parse(Console.ReadLine());
- var dicionary = new Dictionary<string, int>();
- List<KeyValuePair<string, int>> list = new List<KeyValuePair<string, int>>();
- for (int i = 0; i < count; i++)
- {
- string[] str = Console.ReadLine().Split(' ');
- int countStr = int.Parse(str[1]);
- if (dicionary.ContainsKey(str[0]))
- {
- dicionary[str[0]] += countStr;
- }
- else
- {
- dicionary.Add(str[0], countStr);
- }
- }
- count = int.Parse(Console.ReadLine());
- var liststr = new List<string>();
- for (int i = 0; i < count; i++)
- {
- liststr.Add(Console.ReadLine());
- }
- var ls = new List<int>();
- for (int i = 0; i < liststr.Count; i++)
- {
- var str = liststr[i];
- list = new List<KeyValuePair<string, int>>();
- foreach (var el in dicionary)
- {
- if (el.Key.StartsWith(str))
- {
- list.Add(el);
- }
- }
- list.Sort((value1, value2) =>
- {
- if (value1.Value > value2.Value)
- return 1;
- if (value1.Value < value2.Value)
- return -1;
- if (value1.Value == value2.Value)
- {
- int index = 0;
- var str1 = value1.Key.ToLower();
- var str2 = value2.Key.ToLower();
- while (index < str1.Length && index < str2.Length
- && str1[index] == str2[index])
- {
- index++;
- }
- if (index == value1.Key.Length && index != value2.Key.Length)
- {
- return 1;
- }
- if (index == value2.Key.Length && index != value1.Key.Length)
- {
- return -1;
- }
- if (index == value1.Key.Length)
- {
- index--;
- }
- if (str1[index] > str2[index])
- return -1;
- else if (str1[index] < str2[index])
- return 1;
- }
- return 0;
- });
- list.Reverse();
- int ind = 0;
- if (i != 0)
- {
- if (list.Count == 0 || ls[ls.Count - 1] == 0)
- {
- if (ls.Count - 1 != 0)
- Console.WriteLine();
- }
- else
- {
- Console.WriteLine();
- Console.WriteLine();
- }
- }
- else
- {
- if (list.Count == 0)
- {
- Console.WriteLine();
- }
- }
- while (ind < 10 && ind < list.Count)
- {
- if (ind < 9 && ind < list.Count - 1)
- Console.WriteLine(list[ind++].Key);
- else
- Console.Write(list[ind++].Key);
- }
- ls.Add(list.Count);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement