Advertisement
reathh

04.FiveSpecialLetters

Apr 24th, 2014
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.89 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 _04.FiveSpecialLetters
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int start = int.Parse(Console.ReadLine());
  14.             int end = int.Parse(Console.ReadLine());
  15.             char[] chars = { 'a', 'b', 'c', 'd', 'e' };
  16.             bool foundCombination = false;
  17.             List<string> combinations = new List<string>();
  18.  
  19.  
  20.             for (int c1 = 0; c1 < chars.Length; c1++)
  21.             {
  22.                 for (int c2 = 0; c2 < chars.Length; c2++)
  23.                 {
  24.                     for (int c3 = 0; c3 < chars.Length; c3++)
  25.                     {
  26.                         for (int c4 = 0; c4 < chars.Length; c4++)
  27.                         {
  28.                             for (int c5 = 0; c5 < chars.Length; c5++)
  29.                             {
  30.  
  31.                                 string combinationWithRepetitions = string.Concat(chars[c1], chars[c2], chars[c3], chars[c4], chars[c5]);
  32.                                 char[] combination = combinationWithRepetitions.Distinct().ToArray();
  33.  
  34.  
  35.                                 if(Calculate(combination) >= start && Calculate(combination) <= end)
  36.                                 {
  37.                                     foundCombination = true;
  38.                                     combinations.Add(combinationWithRepetitions);
  39.                                 }
  40.  
  41.                             }
  42.                         }
  43.                     }
  44.                 }
  45.             }
  46.  
  47.  
  48.             if (foundCombination)
  49.             {
  50.                 combinations.Sort();
  51.                     foreach (string currentcombination in combinations)
  52.                     {
  53.                         Console.Write(currentcombination + " ");
  54.                     }
  55.             }
  56.             else
  57.             {
  58.                 Console.WriteLine("No");
  59.                 foundCombination = true;
  60.             }
  61.        
  62.  
  63.       }
  64.  
  65.  
  66.         static int Calculate(char[] combination)
  67.         {
  68.             int weight = 0;
  69.             int index = 0;
  70.             for (int i = 1; i <= combination.Length; i++, index++)
  71.             {
  72.                 switch(combination[index])
  73.                 {
  74.                     case 'a':
  75.                         weight += i * 5;
  76.                         break;
  77.                     case 'b':
  78.                         weight += i * -12;
  79.                         break;
  80.                     case 'c':
  81.                         weight += i * 47;
  82.                         break;
  83.                     case 'd':
  84.                         weight += i * 7;
  85.                         break;
  86.                     case 'e':
  87.                         weight += i * -32;
  88.                         break;
  89.                 }
  90.             }
  91.             return weight;
  92.         }
  93.  
  94.  
  95.  
  96.  
  97.  
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement