Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.InteropServices;
- class MagicExchangeableWords
- {
- static void Main()
- {
- {
- string[] input = Console.ReadLine().Split(' ');
- string first = input[0];
- string second = input[1];
- Console.WriteLine(AreEqual(first, second) ? "true" : "false");
- }
- }
- private static bool AreEqual(string a, string b)
- {
- bool areEqual = true;
- var data = new Dictionary<char, char>();
- string aa = "";
- string bb = "";
- if (a.Length == b.Length)
- {
- for (int i = 0; i < a.Length; i++)
- {
- char firstChar = a[i];
- char secondChar = b[i];
- if (!data.ContainsKey(firstChar))
- {
- data.Add(firstChar, secondChar);
- }
- else
- {
- if (!data.ContainsValue(secondChar))
- {
- areEqual = false;
- }
- }
- }
- }
- else if (a.Length != b.Length)
- {
- int minLength = Math.Min(a.Length, b.Length);
- int maxLength = Math.Max(a.Length, b.Length);
- if (minLength == a.Length)
- {
- char[] arrA = a.ToCharArray();
- char[] arrALong = new char[maxLength];
- for (int i = 0; i < maxLength; i++)
- {
- arrALong[i] = arrA[i % minLength];
- }
- aa = new string(arrALong);
- bb = b;
- }
- else if (minLength == b.Length)
- {
- char[] arrB = b.ToCharArray();
- char[] arrBLong = new char[maxLength];
- for (int i = 0; i < maxLength; i++)
- {
- arrBLong[i] = arrB[i % minLength];
- }
- bb = new string(arrBLong);
- aa = a;
- }
- for (int i = 0; i < aa.Length; i++)
- {
- char firstChar = aa[i];
- char secondChar = bb[i];
- if (!data.ContainsKey(firstChar))
- {
- data.Add(firstChar, secondChar);
- }
- else
- {
- if (!data.ContainsValue(secondChar))
- {
- areEqual = false;
- }
- }
- }
- }
- else
- {
- areEqual = false;
- }
- return areEqual;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement