Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- II. LINQ
- 04. Largest 3 Numbers
- Read a list of integers and print the largest 3 of them. If there are less than 3, print all of them.
- Examples
- Input Output Input Output
- 10 30 15 20 50 5 50 30 20 20 30 30 20
- Hints
- • Read an array of integers
- • Order the array using a LINQ query
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace _03WordSynonyms
- {
- class Program
- {
- static void Main(string[] args)
- {
- var listOfIntegers = Console.ReadLine().Split().Select(int.Parse).ToList();
- var sortedNumbers = listOfIntegers.OrderByDescending(x => x).ToList();
- for (int i = 0; i < listOfIntegers.Count; i++)
- {
- if (i < 3)
- {
- Console.Write($"{sortedNumbers[i]} ");
- }
- else
- {
- break;
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment