kidobreva

04. Deserialize String

Aug 4th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 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 _04.Deserialize_String
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             SortedDictionary<int, char> lettersIndex = new SortedDictionary<int, char>();
  14.  
  15.             string input = Console.ReadLine();
  16.  
  17.             while (input != "end")
  18.             {
  19.                 string[] tokens = input.Split(':');
  20.  
  21.                 char letter = tokens[0][0];  //[0] взимаме char стойноста на първия елем, з-то сме сигурни, че той е от тип char
  22.                 int[] indices = tokens[1].Split('/').Select(int.Parse).ToArray();
  23.  
  24.                 foreach (int index in indices)
  25.                 {
  26.                     lettersIndex[index] = letter;
  27.                 }
  28.  
  29.                 input = Console.ReadLine();
  30.             }
  31.  
  32.             Console.WriteLine(lettersIndex.Values.ToArray());
  33.         }
  34.     }
  35. }
Add Comment
Please, Sign In to add comment