Advertisement
YavorGrancharov

Dict_Ref(copy)(dict)

Jul 8th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Dict_Ref
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string[] input = Console.ReadLine().Split().ToArray();
  12.             Dictionary<string, int> output = new Dictionary<string, int>();
  13.  
  14.             while (input[0] != "end")
  15.             {
  16.                 string name = input[0];
  17.                 string secondname = input[2];
  18.                 int value = 0;
  19.  
  20.                 if (int.TryParse(secondname, out value))
  21.                 {
  22.                     output[name] = value;
  23.                 }
  24.                 else
  25.                 {
  26.                     if (output.ContainsKey(secondname))
  27.                     {
  28.                         int secondValue = output[secondname];
  29.                         output[name] = secondValue;
  30.                     }
  31.                 }
  32.                 input = Console.ReadLine().Split(' ').ToArray();
  33.             }
  34.  
  35.             foreach (var x in output)
  36.             {
  37.                 Console.WriteLine($"{x.Key} === {x.Value}");
  38.             }
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement