Advertisement
Guest User

2

a guest
Jun 22nd, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.64 KB | None | 0 0
  1. using System;
  2. //using System.Collections.Generic;
  3. //using System.Linq;
  4. //using System.Text;
  5. //using System.Threading.Tasks;
  6.  
  7. namespace phoneBook
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] phoneNumbers = Console.ReadLine().Split(' ');
  14.             string[] names = Console.ReadLine().Split(' ');
  15.             string[] ownNames = new string[names.Length];
  16.             var index = 0;
  17.             int[] indexInNames = new int[150/*names.Length*/];/*защото незнаеш колко имена
  18.             ще се опитат да търсят и дали са в списъка.Taka си почти сигурен примерно че няма да има
  19.             повече от 50 сърча - затова и ти гърми с рънтаим ерор защото примерите са с по малко сърчове*/
  20.             //var run = true;
  21.             var searches = new string[150]; /*за да събираш сърчовете*/          
  22.             var input = Console.ReadLine();
  23.             while (input != "done")
  24.             {
  25.                 //var input = Console.ReadLine();
  26.                 //if (input == "done")
  27.                 //{
  28.                 //    run = false;
  29.                 //}
  30.                 searches[index] = input;
  31.                 index++;
  32.                 input = Console.ReadLine();
  33.             }
  34.  
  35.             var indexInIndexes = 0;
  36.             for (int i = 0; i < names.Length; i++)
  37.             {
  38.                 for (int y = 0; y < index; y++)/*понеже до сега добавя имена в масив и тепърва почбаш да
  39.                     ги проверяваш с цикъл до индекс си спестяваш следващите примерно 40 итернации*/
  40.                 {
  41.                     if (names[i] == searches[y])
  42.                     {
  43.                         indexInNames[indexInIndexes] = i;
  44.                         indexInIndexes++;
  45.                         break; // за да не върти излишно
  46.                     }
  47.                 }
  48.             }
  49.  
  50.             for (int i = 0; i < indexInIndexes; i++)
  51.             {
  52.                 index = indexInNames[i];/*вземаш стоиноста от i и по нея печаташ и едновременно
  53.                 преизползваш index които не ти трябва повече*/
  54.                 //if (indexInNames[i] == )
  55.                 //{
  56.                     Console.WriteLine(names[index] + " -> " + phoneNumbers[index]);
  57.                 //}
  58.             }
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement