Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Dictionary
- Gencho is in the library, looking for words and their definitions to fill in his dictionary in order to be able to crack an encrypted code and find an ancient relic.
- Your task is to take every word and insert it into the dictionary with its definition. A word may have one or more definitions. You will receive all the words and definitions, separated by " | ", and each word and its definition will be separated by ": ".
- After this you will have to check the words you have in the dictionary. Now you will receive only words, again separated by " | ". For each word you get you will have to print it and all of its definitions, ordered by length of the definition in descending order (if it exists in the dictionary) in the following format:
- "{word}:"
- " –{definition1}"
- " –{definition2}"
- " –{definition3}"
- . . .
- In the end, you will receive one more command, which will be either "End" or "List". If the command is "End", you should break the program. If the command is "List", you should print all of the words, ordered alphabetically, separated by space (" ").
- Input
- Three strings. The first one will have pairs of words and descriptions, separated by " | " and each word separated from its description by ": ". The second string will have only words, separated by " | ". The third string will be a command – either "End" or "List".
- Output
- For each word that is called you have to print it with all of its definitions ordered by their length (descending). In the end you have to print all the words, ordered alphabetically, separated by a single space if you have the command "List". For all of the words you have to print them in the format:
- "{word}:"
- " –{definition1}"
- " –{definition2}"
- " –{definition3}"
- . . .
- Examples
- Input
- programmer: an animal, which turns coffee into code | developer: a magician
- Pesho | Gosho
- List
- Output
- developer programmer
- Input
- tackle: the equipment required for a task or sport | code: write code for a computer program | bit: a small piece, part, or quantity of something | tackle: make determined efforts to deal with a problem | bit: a short time or distance
- bit | code | tackle
- End
- Output
- bit
- -a small piece, part, or quantity of something
- -a short time or distance
- code
- -write code for a computer program
- tackle
- -make determined efforts to deal with a problem
- -the equipment required for a task or sport
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class Program
- {
- public static void Main()
- {
- var firstString = Console.ReadLine().Split(" | ");
- var listDictionary = new SortedDictionary<string, List<string>>();
- foreach (var item in firstString)
- {
- var wordDefinition = item.Split(": ");
- if (!listDictionary.ContainsKey(wordDefinition[0]))
- {
- listDictionary.Add(wordDefinition[0], new List<string>(){$" -{wordDefinition[1]}"});
- }
- else
- {
- listDictionary[wordDefinition[0]].Add($" -{wordDefinition[1]}");
- }
- }
- var secondCheckWordString = Console.ReadLine().Split(" | ");
- foreach (var word in secondCheckWordString)
- {
- if (listDictionary.ContainsKey(word))
- {
- foreach (var item in listDictionary.Where(x => x.Key == word))//Така се посочва да използваме само една(word) от
- //всички ключови думи в речника,
- { //защото иначе ще имаме няколко повтарящи се изхода!
- Console.WriteLine(item.Key);
- Console.WriteLine(string.Join("\n", item.Value.OrderByDescending(x => x.Length))); //Моят начин!
- //foreach (var definition in item.Value.OrderByDescending(x => x.Length))//Друг начин.
- //{
- //Console.WriteLine(definition);
- //}
- }
- }
- }
- var thirdString = Console.ReadLine();
- if (thirdString == "List")
- {
- Console.WriteLine(string.Join(" ", listDictionary.Select(x => x.Key)));//Друг начин.
- //var counter = 0; //Избери(Select) само ключа(думата) от речника(listDictionary)!
- //foreach (var item in listDictionary)
- //{
- // counter++;
- // if (listDictionary.Count != counter)
- // { //Моят начин.
- // Console.Write($"{item.Key} ");
- // }
- // else
- // {
- // Console.WriteLine($"{item.Key}");
- // }
- //}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement