Advertisement
dimipan80

Exam 6. Five Special Letters

Jun 20th, 2014
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.45 KB | None | 0 0
  1. namespace _4.FiveSpecialLetters
  2. {
  3.     using System;
  4.  
  5.     public class FiveSpecialLetters
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             checked
  10.             {
  11.                 long startNum = long.Parse(Console.ReadLine());
  12.                 long endNum = long.Parse(Console.ReadLine());
  13.  
  14.                 bool foundRightSequence = false;
  15.                 for (char i = 'a'; i <= 'e'; i++)
  16.                 {
  17.                     for (char j = 'a'; j <= 'e'; j++)
  18.                     {
  19.                         for (char k = 'a'; k <= 'e'; k++)
  20.                         {
  21.                             for (char m = 'a'; m <= 'e'; m++)
  22.                             {
  23.                                 for (char n = 'a'; n <= 'e'; n++)
  24.                                 {
  25.                                     string word = string.Empty  + i + j + k + m + n;
  26.                                     long weightSeq = WeightOfSingleLetter(i);
  27.                                     long index = 2;
  28.                                     if (j != i)
  29.                                     {
  30.                                         weightSeq += WeightOfSingleLetter(j) * index;
  31.                                         index++;
  32.                                     }
  33.  
  34.                                     if (k != i && k != j)
  35.                                     {
  36.                                         weightSeq += WeightOfSingleLetter(k) * index;
  37.                                         index++;
  38.                                     }
  39.  
  40.                                     if (m != i && m != j && m != k)
  41.                                     {
  42.                                         weightSeq += WeightOfSingleLetter(m) * index;
  43.                                         index++;
  44.                                     }
  45.  
  46.                                     if (n != i && n != j && n != k && n != m)
  47.                                     {
  48.                                         weightSeq += WeightOfSingleLetter(n) * index;                  
  49.                                     }                                      
  50.  
  51.                                     if (weightSeq >= startNum && weightSeq <= endNum)
  52.                                     {
  53.                                         foundRightSequence = true;
  54.                                         Console.Write("{0} ", word);
  55.                                     }
  56.                                 }
  57.                             }
  58.                         }
  59.                     }
  60.                 }
  61.  
  62.                 if (!foundRightSequence)
  63.                 {
  64.                     Console.WriteLine("No");
  65.                 }
  66.             }
  67.         }
  68.  
  69.         private static long WeightOfSingleLetter(char letter)
  70.         {
  71.             checked
  72.             {
  73.                 long weight = 0;
  74.                 switch (letter)
  75.                 {
  76.                     case 'a':
  77.                         weight = 5;
  78.                         break;
  79.                     case 'b':
  80.                         weight = -12;
  81.                         break;
  82.                     case 'c':
  83.                         weight = 47;
  84.                         break;
  85.                     case 'd':
  86.                         weight = 7;
  87.                         break;
  88.                     case 'e':
  89.                         weight = -32;
  90.                         break;
  91.                 }
  92.  
  93.                 return weight;
  94.             }
  95.         }
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement