marekov

FixedEmails

Apr 16th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace FixEmails
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var myDict = new Dictionary<string, string>();
  12.             var result = new Dictionary<string, string>();
  13.  
  14.             while (true)
  15.             {
  16.                 string name = Console.ReadLine();
  17.                 if (name.Equals("stop"))
  18.                 {
  19.                     break;
  20.                 }
  21.  
  22.                 if (!myDict.ContainsKey(name))
  23.                 {
  24.                     myDict.Add(name, "");
  25.                 }
  26.  
  27.                 string email = Console.ReadLine().ToLower();
  28.  
  29.                 if (email.Equals("stop"))
  30.                 {
  31.                     break;
  32.                 }
  33.  
  34.                 if (!email.EndsWith(".us") || !email.EndsWith(".uk"))
  35.                 {
  36.                     myDict[name] = email;
  37.                 }
  38.             }
  39.             foreach (KeyValuePair<string, string> kvp in myDict)
  40.             {
  41.                 if (kvp.Value.EndsWith("uk") == false
  42.                  && kvp.Value.EndsWith("us") == false)
  43.                 {
  44.                     result.Add(kvp.Key,kvp.Value);
  45.                 }
  46.             }
  47.             foreach (KeyValuePair<string, string> kvp in result)
  48.             {
  49.                 Console.WriteLine($"{kvp.Key} -> {kvp.Value}");
  50.             }
  51.         }
  52.     }
  53. }
Add Comment
Please, Sign In to add comment