BorislavBorisov

22.02.Five Special Letters-мое решение 100/100

Nov 7th, 2015
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. class FiveSpecialLetters
  4. {
  5.     static int min, max;
  6.     static List<int> usedNumbers = new List<int>();
  7.     static bool isAnyFound = false;
  8.     static void Main()
  9.     {
  10.         min = int.Parse(Console.ReadLine());
  11.         max = int.Parse(Console.ReadLine());
  12.         char[] vector = new char[5];
  13.         Recursion(vector, 0);
  14.        
  15.         if(!isAnyFound)
  16.         {
  17.             Console.WriteLine("No");
  18.         }
  19.         Console.WriteLine();
  20.     }
  21.     static void Recursion(char[] vector, int index)
  22.     {
  23.         if(index == vector.Length)
  24.         {
  25.             int weight = 0, j = 1;
  26.             for (int i = 0; i < 5; i++)
  27.             {
  28.                 if(usedNumbers.Contains(vector[i]))//ако я има продължава за да не я прибавям към сумата
  29.                 {
  30.                     continue;
  31.                 }
  32.                 usedNumbers.Add(vector[i]);
  33.                 if (vector[i] == 'a')
  34.                 {
  35.                     weight += j * 5;
  36.                 }
  37.                 if (vector[i] == 'b')
  38.                 {
  39.                     weight += j * -12;
  40.                 }
  41.                 if (vector[i] == 'c')
  42.                 {
  43.                     weight += j * 47;
  44.                 }
  45.                 if (vector[i] == 'd')
  46.                 {
  47.                     weight += j * 7;
  48.                 }
  49.                 if (vector[i] == 'e')
  50.                 {
  51.                     weight += j * -32;
  52.                 }
  53.                 j++;
  54.             }
  55.             if(weight >= min && weight <= max)
  56.             {
  57.                 foreach (var item in vector)
  58.                 {
  59.                     Console.Write(item);
  60.                 }
  61.                 Console.Write(" ");
  62.                 isAnyFound = true;
  63.             }
  64.             usedNumbers = new List<int>();//по този начин трия всичко
  65.         }
  66.         else
  67.         {
  68.             for (char i = 'a'; i <= 'e'; i++)
  69.         {
  70.         vector[index] = i;
  71.                 Recursion(vector, index + 1);
  72.             }
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment