Advertisement
SHAMMY1

BAD CAT

May 30th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 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 _5thOneVer2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<char> used = new List<char>() {'0'};
  14.             Dictionary<char, HashSet<char>> digits = new Dictionary<char, HashSet<char>>();
  15.             List<char> number = new List<char>();
  16.  
  17.             int count = int.Parse(Console.ReadLine());
  18.  
  19.             for (int i = 0; i < count; i++)
  20.             {
  21.                 string current = Console.ReadLine();
  22.  
  23.                 char first = current[0];
  24.                 char second = current[current.Length - 1];
  25.  
  26.                 if (current[5] == 'b')
  27.                 {
  28.                     char temp = first;
  29.                     first = second;
  30.                     second = temp;
  31.                 }
  32.  
  33.                 if (digits.ContainsKey(first))
  34.                 {
  35.                     digits[first].Add(second);
  36.                     if (!digits.ContainsKey(second))
  37.                     {
  38.                         digits.Add(second, new HashSet<char>());
  39.                     }
  40.                 }
  41.                 else
  42.                 {
  43.                     digits.Add(first, new HashSet<char>() { second });
  44.                     if (!digits.ContainsKey(second))
  45.                     {
  46.                         digits.Add(second, new HashSet<char>());
  47.                     }
  48.                 }
  49.             }
  50.             char toAdd = FindSmallest(digits, used);
  51.             used.Add(toAdd);
  52.             number.Add(toAdd);
  53.             used.Remove('0');
  54.             for (int i = 0; i < digits.Count - 1; i++)
  55.             {
  56.                 toAdd = FindSmallest(digits, used);
  57.                 used.Add(toAdd);
  58.                 number.Add(toAdd);
  59.  
  60.             }
  61.  
  62.             //if (number[0] == '0')
  63.             //{
  64.             //  number[0] = number[1];
  65.             //  number[1] = '0';
  66.             //}
  67.  
  68.             Console.WriteLine(new string(number.ToArray()));
  69.         }
  70.  
  71.         static char FindSmallest(Dictionary<char, HashSet<char>> disgits, List<char> used)
  72.         {
  73.             char smallest = (char)100;
  74.  
  75.             foreach (var item in disgits)
  76.             {
  77.                 if (!used.Contains(item.Key) && item.Value.Count == 0)
  78.                 {
  79.                     smallest = smallest > item.Key ? item.Key : smallest;
  80.                 }
  81.             }
  82.             foreach (var item in disgits)
  83.             {
  84.                 item.Value.Remove(smallest);
  85.             }
  86.  
  87.             return smallest;
  88.            
  89.         }
  90.  
  91.         static bool Is(List<char> used2, List<char> list)
  92.         {
  93.             int size = Math.Min(used2.Count, list.Count);
  94.  
  95.             for (int i = 0; i < size; i++)
  96.             {
  97.                 if (used2[i] != list[i])
  98.                 {
  99.                     return false;
  100.                 }
  101.             }
  102.  
  103.             return true;
  104.         }
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement