Guest User

Untitled

a guest
Feb 18th, 2017
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.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 _5.Magic_exchangeable_words
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var words = Console.ReadLine().Split(' ').ToList();
  14.             var firstWord = words[0];
  15.             var secondWord = words[1];
  16.             var KeysAndValues = new Dictionary<char, char>();
  17.  
  18.             if (firstWord.Length == secondWord.Length)
  19.             {
  20.                 for (int i = 0; i < firstWord.Length; i++)
  21.                 {
  22.                     if (!KeysAndValues.ContainsKey(firstWord[i]))
  23.                     {
  24.                         KeysAndValues.Add(firstWord[i], secondWord[i]);
  25.                     }
  26.                     else
  27.                     {
  28.                         if (KeysAndValues[firstWord[i]] != secondWord[i])
  29.                         {
  30.                             Console.WriteLine("false");
  31.                             return;
  32.                         }
  33.                     }
  34.                 }
  35.                 Console.WriteLine("true");
  36.             }
  37.             else if (firstWord.Length > secondWord.Length)
  38.             {
  39.                 for (int i = 0; i < secondWord.Length; i++)
  40.                 {
  41.                     if (!KeysAndValues.ContainsKey(firstWord[i]))
  42.                     {
  43.                         KeysAndValues.Add(firstWord[i], secondWord[i]);
  44.                     }
  45.                     else
  46.                     {
  47.                         if (KeysAndValues[firstWord[i]] != secondWord[i])
  48.                         {
  49.                             Console.WriteLine("false");
  50.                             return;
  51.                         }
  52.                     }
  53.                 }
  54.  
  55.                 for (int i = secondWord.Length; i < firstWord.Length; i++)
  56.                 {
  57.                     if (!KeysAndValues.ContainsKey(firstWord[i]))
  58.                     {
  59.                         Console.WriteLine("false");
  60.                         return;
  61.                     }
  62.                 }
  63.                 Console.WriteLine("true");
  64.             }
  65.             else
  66.             {
  67.                 for (int i = 0; i < firstWord.Length; i++)
  68.                 {
  69.                     if (!KeysAndValues.ContainsKey(firstWord[i]))
  70.                     {
  71.                         KeysAndValues.Add(firstWord[i], secondWord[i]);
  72.                     }
  73.                     else
  74.                     {
  75.                         if (KeysAndValues[firstWord[i]] != secondWord[i])
  76.                         {
  77.                             Console.WriteLine("false");
  78.                             return;
  79.                         }
  80.                     }
  81.                 }
  82.  
  83.                 for (int i = firstWord.Length; i < secondWord.Length; i++)
  84.                 {
  85.                     if (!KeysAndValues.ContainsValue(secondWord[i]))
  86.                     {
  87.                         Console.WriteLine("false");
  88.                         return;
  89.                     }
  90.                 }
  91.                 Console.WriteLine("true");
  92.             }
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment