Advertisement
elena1234

Phonebook

Oct 2nd, 2020
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Phonebook
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             List<string> listOfNumbers = Console.ReadLine().Split().ToList();
  12.             List<string> listOfNames = Console.ReadLine().Split().ToList();
  13.             List<string> resultNames = new List<string>();
  14.             List<string> resultNumbers = new List<string>();
  15.  
  16.             string name = string.Empty;
  17.            
  18.             while((name=Console.ReadLine()) != "done")
  19.             {
  20.                 if (listOfNames.Exists(x => x == name))
  21.                 {
  22.                     int indexOfPersonalName=listOfNames.IndexOf(name);
  23.                     string numberOfPersonalName = listOfNumbers[indexOfPersonalName];
  24.                     resultNames.Add(name);
  25.                     resultNumbers.Add(numberOfPersonalName);
  26.                 }
  27.             }
  28.  
  29.             for (int i = 0; i < resultNames.Count; i++)
  30.             {
  31.                 Console.WriteLine($"{resultNames[i]} -> {resultNumbers[i]}");
  32.  
  33.             }
  34.         }
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement