Exercises: Lists and Matrices - 7. Square Numbers
Задачата е следната: Read a list of integers and extract square numbers from it and print them in descending order. A square number is an integer which is the square of any integer. For example, 1, 4, 9, 16 are square numbers.
Получавам 80/100 и не мога да си открия грешката. Явно нещо пропускам.
Ето кода:
static void Main(string[] args) { List<long> nums = Console.ReadLine().Split(' ').Select(long.Parse).ToList(); List<long> result = new List<long>(); nums.Sort(); nums.Reverse(); for (int i = 0; i <nums.Count; i++) if (Math.Sqrt(nums[i]) == Math.Truncate(Math.Sqrt(nums[i]))) result.Add((nums[i])); Console.WriteLine(string.Join(" ",result)); }