Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _5.Magic_exchangeable_words
- {
- class Program
- {
- static void Main(string[] args)
- {
- var words = Console.ReadLine().Split(' ').ToList();
- var firstWord = words[0];
- var secondWord = words[1];
- var KeysAndValues = new Dictionary<char, char>();
- if (firstWord.Length == secondWord.Length)
- {
- for (int i = 0; i < firstWord.Length; i++)
- {
- if (!KeysAndValues.ContainsKey(firstWord[i]))
- {
- KeysAndValues.Add(firstWord[i], secondWord[i]);
- }
- else
- {
- if (KeysAndValues[firstWord[i]] != secondWord[i])
- {
- Console.WriteLine("false");
- return;
- }
- }
- }
- Console.WriteLine("true");
- }
- else if (firstWord.Length > secondWord.Length)
- {
- for (int i = 0; i < secondWord.Length; i++)
- {
- if (!KeysAndValues.ContainsKey(firstWord[i]))
- {
- KeysAndValues.Add(firstWord[i], secondWord[i]);
- }
- else
- {
- if (KeysAndValues[firstWord[i]] != secondWord[i])
- {
- Console.WriteLine("false");
- return;
- }
- }
- }
- for (int i = secondWord.Length; i < firstWord.Length; i++)
- {
- if (!KeysAndValues.ContainsKey(firstWord[i]))
- {
- Console.WriteLine("false");
- return;
- }
- }
- Console.WriteLine("true");
- }
- else
- {
- for (int i = 0; i < firstWord.Length; i++)
- {
- if (!KeysAndValues.ContainsKey(firstWord[i]))
- {
- KeysAndValues.Add(firstWord[i], secondWord[i]);
- }
- else
- {
- if (KeysAndValues[firstWord[i]] != secondWord[i])
- {
- Console.WriteLine("false");
- return;
- }
- }
- }
- for (int i = firstWord.Length; i < secondWord.Length; i++)
- {
- if (!KeysAndValues.ContainsValue(secondWord[i]))
- {
- Console.WriteLine("false");
- return;
- }
- }
- Console.WriteLine("true");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment