Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- //Read a list of integers in range [0…1000] and print them in ascending order along with their number of occurrences.
- namespace Count_numbers_dictionary
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
- Dictionary<int, int> countNumbers = new Dictionary<int, int>();
- foreach (var number in numbers)
- {
- if (!countNumbers.ContainsKey(number))
- {
- countNumbers.Add(number, 0);
- }
- countNumbers[number]++;
- }
- countNumbers.OrderBy(i => i.Key);
- foreach (var number in countNumbers.OrderBy(i => i.Key))
- {
- Console.WriteLine($"{number.Key} -> {number.Value}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement