Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class NakovsMatching
- {
- static void Main()
- {
- string firstWord = Console.ReadLine();
- string secondWord = Console.ReadLine();
- long d = long.Parse(Console.ReadLine());
- bool matchFound = false;
- for (int i = 0; i < firstWord.Length - 1; i++)
- {
- long firstWordLeftSum = 0;
- long firstWordRightSum = 0;
- List<char> firstLeft = new List<char>();
- List<char> firstRight = new List<char>();
- int rightStartIndexFirstWord = i + 1;
- for (int k = 0; k < rightStartIndexFirstWord; k++)
- {
- firstWordLeftSum += firstWord[k];
- firstLeft.Add(firstWord[k]);
- }
- for (int m = rightStartIndexFirstWord; m < firstWord.Length; m++)
- {
- firstWordRightSum += firstWord[m];
- firstRight.Add(firstWord[m]);
- }
- for (int j = 0; j < secondWord.Length - 1; j++)
- {
- long secondWordLeftSum = 0;
- long secondWordRightSum = 0;
- List<char> secondLeft = new List<char>();
- List<char> secondRight = new List<char>();
- int rightStartIndexSecondWord = j + 1;
- for (int n = 0; n < rightStartIndexSecondWord; n++)
- {
- secondWordLeftSum += secondWord[n];
- secondLeft.Add(secondWord[n]);
- }
- for (int p = rightStartIndexSecondWord; p < secondWord.Length; p++)
- {
- secondWordRightSum += secondWord[p];
- secondRight.Add(secondWord[p]);
- }
- long diff = Math.Abs(firstWordLeftSum * secondWordRightSum - firstWordRightSum * secondWordLeftSum);
- if (diff <= d)
- {
- string firstResult = string.Join("", firstLeft) + "|" + string.Join("", firstRight);
- string secondResult = string.Join("", secondLeft) + "|" + string.Join("", secondRight);
- Console.WriteLine("({0}) matches ({1}) by {2} nakovs", firstResult, secondResult, diff);
- matchFound = true;
- }
- }
- }
- if (matchFound == false)
- {
- Console.WriteLine("No");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement