Advertisement
optybg

Untitled

Apr 6th, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _01SerializeString
  6. {
  7.     public class SerializeString
  8.     {
  9.         public static void Main()
  10.         {
  11.             var inputString = Console.ReadLine();
  12.  
  13.             var outputChars = new Dictionary<char, List<int>>();
  14.  
  15.             for (int i = 0; i < inputString.Length; i++)
  16.             {
  17.                 if (!outputChars.ContainsKey(inputString[i]))
  18.                 {
  19.                     outputChars[inputString[i]] = new List<int>();
  20.                 }
  21.                 outputChars[inputString[i]].Add(i);
  22.                                
  23.             }
  24.  
  25.             foreach (var character in outputChars)
  26.             {
  27.                 Console.WriteLine($"{character.Key}:" + string.Join("/", character.Value));
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement