Advertisement
fbinnzhivko

04.00 Nakovs Matching

Apr 16th, 2016
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.35 KB | None | 0 0
  1. using System;
  2. class Program
  3. {
  4.     static void Main()
  5.     {
  6.         string first = Console.ReadLine().ToLower();
  7.         string second = Console.ReadLine().ToLower();
  8.  
  9.         int limit = int.Parse(Console.ReadLine());
  10.  
  11.         bool noGoodMatch = true;
  12.         int weightFirst = 0;
  13.         int weightSecond = 0;
  14.         int nakovs = 0;
  15.  
  16.         for (int i = 0; i < first.Length; i++){weightFirst += first[i];}
  17.         for (int i = 0; i < second.Length; i++){weightSecond += second[i];}
  18.  
  19.         int aLeft = first[0];
  20.  
  21.         for (int i = 1; i < first.Length; i++)
  22.         {
  23.             int bLeft = second[0];
  24.             for (int j = 1; j < second.Length; j++)
  25.             {
  26.                 nakovs = Math.Abs(aLeft * (weightSecond - bLeft) - bLeft * (weightFirst - aLeft));
  27.                 if (nakovs <= limit)
  28.                 {
  29.                     Console.WriteLine("({0}|{1}) matches ({2}|{3}) by {4} nakovs",
  30.                         first.Substring(0, i), first.Substring(i, first.Length - i),
  31.                         second.Substring(0, j), second.Substring(j, second.Length - j), nakovs);
  32.                     noGoodMatch = false;
  33.  
  34.                 }
  35.                 bLeft += second[j];
  36.             }
  37.             aLeft += first[i];
  38.         }
  39.         if (noGoodMatch)
  40.         {
  41.             Console.WriteLine("No");
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement