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.Text;
- using System.Threading.Tasks;
- namespace Magic_exchangeable_words
- {
- class Program
- {
- static void AppendedNumber(StringBuilder sb, int[] wordIntCopy)
- {
- foreach (var numb in wordIntCopy)
- {
- sb.Append(numb);
- }
- }
- static bool CompareOfStringForReplease(StringBuilder sbMinLength, StringBuilder sbMaxLength)
- {
- string extract = sbMaxLength.ToString().Substring(0, sbMinLength.Length);
- char[] endExtract = sbMaxLength.ToString().Substring(sbMinLength.Length).ToCharArray();
- char[] sbCharArray = sbMinLength.ToString().ToCharArray();
- if (!sbMinLength.ToString().Equals(extract))
- {
- return false;
- }
- else
- {
- bool checkContains = false;
- for (int i = 0; i < endExtract.Length; i++)
- {
- if (!sbCharArray.Contains(endExtract[i]))
- {
- checkContains = true;
- break;
- }
- }
- if (checkContains)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- }
- static void Main(string[] args)
- {
- string[] arr = Console.ReadLine().Trim().Split();
- StringBuilder sb1 = new StringBuilder();
- StringBuilder sb2 = new StringBuilder();
- bool check = false;
- bool result = default(bool);
- int savePosition = 0;
- for (int n = 0; n < arr.Length; n++)
- {
- char[] word1 = arr[n].ToCharArray();
- int[] wordInt = word1.Select(x => Convert.ToInt32(x)).ToArray();
- int[] wordIntCopy = new int[wordInt.Length];
- for (int i = 0; i < wordIntCopy.Length; i++)
- {
- wordIntCopy[i] = i + 1;
- }
- for (int i = 0; i < wordInt.Length - 1; i++)
- {
- for (int j = i + 1; j < wordInt.Length; j++)
- {
- if ((wordInt[i] == wordInt[j])&&(wordIntCopy[i]!=wordIntCopy[j]))
- {
- wordIntCopy[j] = i + 1;
- }
- }
- for (int m = i; m < wordIntCopy.Length-1; m++)
- {
- if (wordIntCopy[m]!=wordIntCopy[m+1])
- {
- savePosition = m;
- check = true;
- break;
- }
- }
- if (check)
- {
- i = savePosition;
- }
- check = false;
- }
- if (n==0)
- {
- AppendedNumber(sb1, wordIntCopy);
- }
- else
- {
- AppendedNumber(sb2, wordIntCopy);
- }
- }
- if (sb1.Length==sb2.Length)
- {
- if (sb1.Equals(sb2))
- {
- Console.WriteLine(true.ToString().ToLower());
- }
- else
- {
- Console.WriteLine(false.ToString().ToLower());
- }
- }
- else
- {
- if (sb1.Length < sb2.Length)
- {
- result = CompareOfStringForReplease(sb1, sb2);
- }
- else
- {
- result = CompareOfStringForReplease(sb2, sb1);
- }
- Console.WriteLine(result.ToString().ToLower());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement