Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System;
- using System.Linq;
- class Program
- {
- static void Main(string[] args)
- {
- //input:
- //1 1 2 3 4 5 6 6 7 8
- int[] numbers = Console.ReadLine()
- .Split(' ')
- .Select(int.Parse)
- .ToArray();
- var count = new Dictionary<double, int>();
- foreach (var num in numbers)
- {
- if (count.ContainsKey(num))
- {
- count[num]++;
- }
- else
- {
- count[num] = 1;
- }
- }
- foreach (var num in count)
- {
- Console.WriteLine($"{num.Key} keys -> {num.Value} values");
- }
- //output:
- //1 keys -> 2 values
- //2 keys -> 1 values
- //3 keys -> 1 values
- //4 keys -> 1 values
- //5 keys -> 1 values
- //6 keys -> 2 values
- //7 keys -> 1 values
- //8 keys -> 1 values
- Console.ReadLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement