Advertisement
g-stoyanov

%u0428%u043E%u043A%u043E%u043B%u0430%u0434%u0438

Dec 28th, 2012
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.97 KB | None | 0 0
  1. using System;
  2.  
  3. class Contest76Task2Chocolates
  4. {
  5.     static void Main()
  6.     {
  7.         string[] firstLineInput = Console.ReadLine().Split(' ');
  8.         string[] secondLineInput = Console.ReadLine().Split(' ');
  9.         int numberOfNumbers = int.Parse(firstLineInput[0]);
  10.         int numberOfDifferent = int.Parse(firstLineInput[1]);
  11.         int tempLong = 0;
  12.         int tempDifferent = 0;
  13.         int minLength = int.MaxValue;
  14.         bool tempCheck = false;
  15.         string[] tempDifferentNumbers = new string[numberOfDifferent];
  16.         for (int i = 0; i < numberOfNumbers - (numberOfDifferent - 1); i++)
  17.         {
  18.             if (minLength == numberOfDifferent)
  19.             {
  20.                 break;
  21.             }
  22.             if (secondLineInput[i] == secondLineInput[i + 1])
  23.             {
  24.                 continue;
  25.             }
  26.             tempLong = 0;
  27.             tempDifferent = 0;
  28.             tempDifferentNumbers = new string[numberOfDifferent];
  29.             for (int x = i; x <= numberOfNumbers; x++)
  30.             {
  31.                 tempCheck = false;
  32.                 if (tempDifferent == numberOfDifferent)
  33.                 {
  34.                     if (tempLong < minLength)
  35.                     {
  36.                         minLength = tempLong;
  37.                     }
  38.                     break;
  39.                 }
  40.                 else if (x != numberOfNumbers)
  41.                 {
  42.                     tempLong++;
  43.                     for (int y = 0; y < numberOfDifferent; y++)
  44.                     {
  45.                         if (secondLineInput[x] == tempDifferentNumbers[y])
  46.                         {
  47.                             tempCheck = true;
  48.                             break;
  49.                         }
  50.                     }
  51.                     if (!tempCheck)
  52.                     {
  53.                         tempDifferentNumbers[tempDifferent] = secondLineInput[x];
  54.                         tempDifferent++;
  55.                     }
  56.                 }
  57.             }
  58.         }
  59.         Console.WriteLine(minLength);
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement