Advertisement
dim4o

NakovsMatching

Jul 28th, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. using System;
  2. namespace NakovsMatching
  3. {
  4.     class NakovsMatching
  5.     {
  6.         static void Main()
  7.         {
  8.             string aWord = Console.ReadLine();
  9.             string bWord = Console.ReadLine();
  10.             int limitNum = int.Parse(Console.ReadLine());
  11.             bool exist = false;
  12.             for (int i = 1; i < aWord.Length; i++)
  13.             {
  14.                 string aLeft = aWord.Substring(0,i);
  15.                 string aRight = aWord.Substring(i, aWord.Length - i  );
  16.  
  17.                 for (int k = 1; k < bWord.Length; k++)
  18.                 {
  19.                     string bLeft = bWord.Substring(0, k);
  20.                     string bRight = bWord.Substring(k, bWord.Length - k);
  21.  
  22.                     long nakovs = Math.Abs(getWight(aLeft) * getWight(bRight)
  23.                         - getWight(aRight) * getWight(bLeft));
  24.                     if (nakovs <= limitNum)
  25.                     {
  26.                         Console.WriteLine("({0}|{1}) matches ({2}|{3}) by {4} nakovs",
  27.                             aLeft, aRight, bLeft, bRight, nakovs);
  28.                         exist = true;
  29.                     }
  30.                 }
  31.             }
  32.             if (exist == false)
  33.             {
  34.                 Console.WriteLine("No");
  35.             }  
  36.         }
  37.         static int getWight(string word)
  38.         {
  39.             int weight = 0;
  40.             foreach (var item in word)
  41.             {
  42.                 weight += (int)item;
  43.             }
  44.             return weight;
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement