Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class MagicExchangeableWords
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- string firstWord = input.Trim().Split(' ')[0].ToLower();
- string secondWord = input.Trim().Split(' ')[1].ToLower();
- Dictionary<char, char> exchane = new Dictionary<char, char>();
- bool isEchangebale = true;
- if (firstWord.Length == secondWord.Length)
- {
- for (int i = 0; i < firstWord.Length; i++)
- {
- if (!exchane.ContainsKey(firstWord.ElementAt(i)))
- {
- exchane[firstWord.ElementAt(i)] = secondWord.ElementAt(i);
- }
- else
- {
- if (exchane[firstWord.ElementAt(i)] != secondWord.ElementAt(i))
- {
- isEchangebale = false;
- }
- }
- }
- }
- else if (firstWord.Length > secondWord.Length)
- {
- for (int i = 0; i < secondWord.Length; i++)
- {
- if (!exchane.ContainsKey(secondWord.ElementAt(i)))
- {
- exchane[secondWord.ElementAt(i)] = firstWord.ElementAt(i);
- }
- else
- {
- if (exchane[secondWord.ElementAt(i)] != firstWord.ElementAt(i))
- {
- isEchangebale = false;
- }
- }
- }
- for (int i = secondWord.Length; i < firstWord.Length; i++)
- {
- if (!exchane.ContainsValue(firstWord.ElementAt(i)))
- {
- isEchangebale = false;
- }
- }
- }
- else
- {
- for (int i = 0; i < firstWord.Length; i++)
- {
- if (!exchane.ContainsKey(firstWord.ElementAt(i)))
- {
- exchane[firstWord.ElementAt(i)] = secondWord.ElementAt(i);
- }
- else
- {
- if (exchane[firstWord.ElementAt(i)] != secondWord.ElementAt(i))
- {
- isEchangebale = false;
- }
- }
- }
- for (int i = firstWord.Length; i < secondWord.Length; i++)
- {
- if (!exchane.ContainsValue(secondWord.ElementAt(i)))
- {
- isEchangebale = false;
- }
- }
- }
- Console.WriteLine(isEchangebale.ToString().ToLower());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement