Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class FiveSpecialLetters
- {
- static void Main()
- {
- int minValue = int.Parse(Console.ReadLine());
- int maxValue = int.Parse(Console.ReadLine());
- int result = 0;
- for (char i1 = 'a'; i1 <= 'e'; i1++)
- {
- for (char i2 = 'a'; i2 <= 'e'; i2++)
- {
- for (char i3 = 'a'; i3 <= 'e'; i3++)
- {
- for (char i4 = 'a'; i4 <= 'e'; i4++)
- {
- for (char i5 = 'a'; i5 <= 'e'; i5++)
- {
- string str = "" + i1 + i2 + i3 + i4 + i5;
- int weight = CalcWeight(str);
- if(weight <= maxValue && weight >= minValue)
- {
- if(result > 0)//този иф е за да се отпечата плътно до конзолата
- {
- Console.Write(" ");
- }
- result++;
- Console.Write(str);
- }
- }
- }
- }
- }
- }
- if(result == 0)
- {
- Console.WriteLine("No");
- }
- Console.WriteLine();
- }
- static int CalcWeight(string str)
- {
- bool[] used = new bool[(int)'e' + 1];
- int index = 1;
- int weight = 0;
- for (int i = 0; i < str.Length; i++)
- {
- char letter = str[i];
- if(!used[letter])
- {
- weight += index * Calc(letter);
- index++;
- used[letter] = true;
- }
- }
- return weight;
- }
- static int Calc(char letter)
- {
- switch(letter)
- {
- case 'a' : return 5;
- case 'b' : return -12;
- case 'c' : return 47;
- case 'd' : return 7;
- case 'e' : return -32;
- }
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment