BorislavBorisov

22.Five Special Letters

Oct 3rd, 2015
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 KB | None | 0 0
  1. using System;
  2. class FiveSpecialLetters
  3. {
  4.     static void Main()
  5.     {
  6.         int minValue = int.Parse(Console.ReadLine());
  7.         int maxValue = int.Parse(Console.ReadLine());
  8.         int result = 0;
  9.         for (char i1 = 'a'; i1 <= 'e'; i1++)
  10.         {
  11.             for (char i2 = 'a'; i2 <= 'e'; i2++)
  12.             {
  13.  
  14.                 for (char i3 = 'a'; i3 <= 'e'; i3++)
  15.                 {
  16.  
  17.                     for (char i4 = 'a'; i4 <= 'e'; i4++)
  18.                     {
  19.  
  20.                         for (char i5 = 'a'; i5 <= 'e'; i5++)
  21.                         {
  22.                             string str = "" + i1 + i2 + i3 + i4 + i5;
  23.                             int weight = CalcWeight(str);
  24.                             if(weight <= maxValue && weight >= minValue)
  25.                             {
  26.                                 if(result > 0)//този иф е за да се отпечата плътно до конзолата
  27.                                 {
  28.                                     Console.Write(" ");
  29.                                 }
  30.                                 result++;
  31.                                 Console.Write(str);
  32.                             }
  33.                         }  
  34.                     }  
  35.                 }  
  36.             }  
  37.         }
  38.         if(result == 0)
  39.         {
  40.             Console.WriteLine("No");
  41.         }
  42.         Console.WriteLine();
  43.     }
  44.  
  45.     static int CalcWeight(string str)
  46.     {
  47.         bool[] used = new bool[(int)'e' + 1];
  48.         int index = 1;
  49.         int weight = 0;
  50.         for (int i = 0; i < str.Length; i++)
  51.         {
  52.             char letter = str[i];
  53.             if(!used[letter])
  54.             {
  55.                 weight += index * Calc(letter);
  56.                 index++;
  57.                 used[letter] = true;
  58.             }
  59.         }
  60.         return weight;
  61.     }
  62.     static int Calc(char letter)
  63.     {
  64.         switch(letter)
  65.         {
  66.             case 'a' : return 5;
  67.             case 'b' : return -12;
  68.             case 'c' : return 47;
  69.             case 'd' : return 7;
  70.             case 'e' : return -32;
  71.         }
  72.         return 0;
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment