Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace RegisteredUSers
- {
- internal class Program
- {
- public static void Main(string[] args)
- {
- string input = Console.ReadLine();
- Dictionary<string, string> dic = new Dictionary<string, string>();
- Dictionary<string, string> dic2 = new Dictionary<string, string>();
- while (input != "end")
- {
- string[] inputTokens =
- input.Split(new string[] { " -> " }, StringSplitOptions.RemoveEmptyEntries);
- string key = inputTokens[0];
- string value = inputTokens[1];// <= хубаво е да е коректния индекс :)
- // според мен това е по добър вариянт за добавяне и променяне на стоиности в
- // в речник
- // проверяваш дали НЕсъществува и създаваш ключа и след проверката му
- // задаваш стоиност.
- if (!dic.ContainsKey(key))
- {
- dic[key] = string.Empty;
- }
- dic[key] = value;
- input = Console.ReadLine();
- }
- string defaultValue = Console.ReadLine();
- foreach (var item in dic)
- {
- if (item.Value == "null")
- {
- dic2.Add(item.Key, defaultValue);
- }
- //dic.Remove(item.Value);
- }
- //когато го сортираш или променяш трябва да го зададеш като стоиност на себе си или
- //или на друга колекция
- dic = dic.Where(x => x.Value != "null")
- .OrderByDescending(x => x.Value.Length)
- .ToDictionary(x => x.Key, x => x.Value);
- foreach (var item in dic)
- {
- Console.WriteLine($"{item.Key} <-> {item.Value}");
- }
- foreach (var item in dic2)
- {
- Console.WriteLine($"{item.Key} <-> {item.Value}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement