Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace AlphaNumbers
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Alpha numbers are a very special kind of numbers because they follow a very special rule - the biggest non-negative difference between
- //all pairs must be larger than the last digit of the sum of all digits.Sounds hard?
- //For example, 186 is an alpha number.
- //The non-negative differences are 8 - 1 = 7, 8 - 6 = 2 and 6 - 1 = 5.
- //The sum of all digits is 1 + 8 + 6 = 15.
- //The biggest difference 7 is larger than the last digit of 15.
- //Input
- //Exactly 7 numbers, each on a new line.
- //Output
- //Each alpha number on a new line, in the order given.
- //Constraints
- //100 <= number <= 999
- //Sample tests
- //Input
- //186
- //144
- //782
- //764
- //882
- //909
- //511
- //Output
- //186
- //909
- //Input
- //135
- //357
- //791
- //357
- //913
- //579
- //135
- //Output
- //791
- //913
- //579
- List<int> output = new List<int>();
- for (int i = 0; i < 7; i++)
- {
- int input = int.Parse(Console.ReadLine());
- int firstDigit = input % 10;
- int secondDigit = (input / 10) % 10;
- int thirdDigit = (input / 100) % 10;
- int largNum = Math.Max(firstDigit, Math.Max(secondDigit, thirdDigit));
- int smallerNum = Math.Min(firstDigit, Math.Min(secondDigit, thirdDigit));
- int middleNum = firstDigit + secondDigit + thirdDigit - largNum - smallerNum;
- int biggestDiff = largNum - smallerNum;
- int digitsSumLastNum = (firstDigit + secondDigit + thirdDigit) % 10;
- if (biggestDiff > digitsSumLastNum)
- {
- output.Add(input);
- }
- }
- foreach (var item in output)
- {
- Console.WriteLine(item);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment