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