Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace NakovsMatching
- {
- class NakovsMatching
- {
- static void Main()
- {
- string aWord = Console.ReadLine();
- string bWord = Console.ReadLine();
- int limitNum = int.Parse(Console.ReadLine());
- bool exist = false;
- for (int i = 1; i < aWord.Length; i++)
- {
- string aLeft = aWord.Substring(0,i);
- string aRight = aWord.Substring(i, aWord.Length - i );
- for (int k = 1; k < bWord.Length; k++)
- {
- string bLeft = bWord.Substring(0, k);
- string bRight = bWord.Substring(k, bWord.Length - k);
- long nakovs = Math.Abs(getWight(aLeft) * getWight(bRight)
- - getWight(aRight) * getWight(bLeft));
- if (nakovs <= limitNum)
- {
- Console.WriteLine("({0}|{1}) matches ({2}|{3}) by {4} nakovs",
- aLeft, aRight, bLeft, bRight, nakovs);
- exist = true;
- }
- }
- }
- if (exist == false)
- {
- Console.WriteLine("No");
- }
- }
- static int getWight(string word)
- {
- int weight = 0;
- foreach (var item in word)
- {
- weight += (int)item;
- }
- return weight;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement