stefan1919

nakov matching

Aug 27th, 2015
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string aInput = Console.ReadLine();
  14.             string bInput = Console.ReadLine();
  15.             string aFirstPart = string.Empty;
  16.             string aSecondPart = string.Empty;
  17.             string bFirstPart = string.Empty;
  18.             string bSecondPart = string.Empty;
  19.             int acounter = 1;
  20.             int bcounter = 1;
  21.             int d = int.Parse(Console.ReadLine());
  22.             int matches = 0;
  23.             for (int i = 0; i < aInput.Length - 1; i++)
  24.             {
  25.                
  26.                
  27.                 aFirstPart += aInput[i];
  28.                 int afirstPartSum = 0;
  29.                 foreach (var letter in aFirstPart)
  30.                 {
  31.                     afirstPartSum += (int)letter;
  32.                 }
  33.                 aSecondPart = aInput.Substring(i + 1);
  34.                 int asecondPartSum = 0;
  35.                 foreach (var letter in aSecondPart)
  36.                 {
  37.                     asecondPartSum += (int)letter;
  38.                 }
  39.                 acounter++;
  40.                 for (int j = 0; j < bInput.Length - 1; j++)
  41.                 {
  42.                     bFirstPart += bInput[j];
  43.                     int bfirstPartSum = 0;
  44.                     foreach (var letter in bFirstPart)
  45.                     {
  46.                         bfirstPartSum += (int)letter;
  47.                     }
  48.                     bSecondPart = bInput.Substring(j + 1);
  49.                     int bsecondSum = 0;
  50.                     foreach (var letter in bSecondPart)
  51.                     {
  52.                         bsecondSum += (int)letter;
  53.                     }
  54.                     bcounter++;
  55.                     int sum = (int)(Math.Abs((afirstPartSum * bsecondSum) - (bfirstPartSum * asecondPartSum)));
  56.                     if (sum <= d)
  57.                     {
  58.                         Console.WriteLine("({0}|{1}) matches ({2}|{3}) by {4} nakovs", aFirstPart,aSecondPart,bFirstPart,bSecondPart,sum);
  59.                         matches++;
  60.                     }
  61.                    
  62.                    
  63.  
  64.                 }
  65.                 bFirstPart = string.Empty;
  66.                 bSecondPart = string.Empty;
  67.                
  68.             }
  69.             if (matches == 0)
  70.             {
  71.                 Console.WriteLine("No");  
  72.             }
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment