Advertisement
Guest User

c#basics

a guest
Jul 7th, 2014
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.96 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. class FiveSpecialLetters
  8. {
  9.     public static List<char> chars = new List<char> { 'a', 'b', 'c', 'd', 'e' };
  10.     public static List<int> weights = new List<int> { 5, -12, 47, 7, -32 };
  11.     static void Main(string[] args)
  12.     {
  13.         int start = int.Parse(Console.ReadLine());
  14.         int end = int.Parse(Console.ReadLine());
  15.         bool answer = false;
  16.  
  17.         for (char a = 'a'; a <= 'e'; a++)
  18.         {
  19.             for (char b = 'a'; b <= 'e'; b++)
  20.             {
  21.                 for (char c = 'a'; c <= 'e'; c++)
  22.                 {
  23.                     for (char d = 'a'; d <= 'e'; d++)
  24.                     {
  25.                         for (char e = 'a'; e <= 'e'; e++)
  26.                         {
  27.                             string specialLetters = a.ToString() + b.ToString() + c.ToString() + d.ToString() + e.ToString();
  28.                             if (IsAnswer(CalculateWeight(specialLetters), start, end))
  29.                             {
  30.                                 answer = true;
  31.                                 Console.Write(specialLetters + " ");
  32.                             }
  33.                         }
  34.                     }
  35.                 }
  36.             }
  37.         }
  38.  
  39.         if (!answer)
  40.         {
  41.             Console.WriteLine("No");
  42.         }
  43.     }
  44.     static int CalculateWeight(string str)
  45.     {
  46.         int weight = 0;
  47.         List<char> letters = new List<char>();
  48.         foreach (var letter in str)
  49.         {
  50.             if (!letters.Contains(letter))
  51.             {
  52.                 letters.Add(letter);
  53.             }
  54.         }
  55.         for (int i = 0; i < letters.Count; i++)
  56.         {
  57.             weight += (i + 1) * weights[chars.IndexOf(letters[i])];
  58.         }
  59.         return weight;
  60.     }
  61.     static bool IsAnswer(int weight, int start, int end)
  62.     {
  63.         bool answer = weight >= start && weight <= end;
  64.         return answer;
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement