Advertisement
NelIfandieva

RemoveEntryIfContainsSpecificString_Dict_Ex04

Feb 26th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Globalization;
  5.  
  6. namespace Feb26_2018
  7. {
  8.     class MainClass
  9.     {
  10.         /* */
  11.  
  12.         public static void Main()
  13.         {
  14.             //int k = int.Parse(Console.ReadLine());
  15.             //var input = Console.ReadLine()
  16.             //                   .Split()
  17.             //                   .Select(double.Parse)
  18.             //                   .ToList();
  19.  
  20.             //var firstK = input.Take(k);
  21.             //var asd = input.ToArray().Reverse();
  22.             //Console.WriteLine(asd);
  23.             char[] sep = {' '};
  24.             Dictionary<string, string> peoplesEmailAddresses = new Dictionary<string, string>();
  25.             string personsName;
  26.             string personsEmail;
  27.             while((personsName = Console.ReadLine().ToLower()) != "stop")
  28.             {
  29.                 personsEmail = Console.ReadLine();
  30.                 peoplesEmailAddresses[personsName] = personsEmail;
  31.                 string dotUk = ".uk";
  32.                 string dotUS = ".us";
  33.                 CultureInfo validate = new CultureInfo("en-US");
  34.                 if(personsEmail.EndsWith(dotUk, true, validate) == false || personsEmail.EndsWith(dotUS, true, validate) == false)
  35.                 {
  36.                     continue;
  37.                 }
  38.                 if (peoplesEmailAddresses.ContainsKey(personsName))
  39.                 {
  40.                     peoplesEmailAddresses[personsName] = personsEmail;
  41.                 }
  42.                 else
  43.                 {
  44.                     peoplesEmailAddresses.Add(personsName, personsEmail);
  45.                 }
  46.             }
  47.             foreach (var contactInfo in peoplesEmailAddresses)
  48.             {
  49.                 var name = contactInfo.Key;
  50.                 var email = contactInfo.Value;
  51.                 Console.WriteLine("{0} -> {1}", name, email);
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement