Advertisement
desislava_topuzakova

Untitled

Apr 12th, 2020
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Demo
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.             List<Person> people = new List<Person>();
  15.  
  16.             for (int i = 1; i <= n; i++)
  17.             {
  18.                 string input = Console.ReadLine();
  19.                 string name = input.Split(" ")[0];
  20.                 int age = int.Parse(input.Split(" ")[1]);
  21.                 Person person = new Person(name, age);
  22.                 people.Add(person);
  23.             }
  24.  
  25.             Dictionary<string, int> peopleOver30 = new Dictionary<string, int>();
  26.             foreach(Person person in people)
  27.             {
  28.                 if(person.Age > 30)
  29.                 {
  30.                     peopleOver30.Add(person.Name, person.Age);
  31.                 }
  32.             }
  33.  
  34.             peopleOver30 = peopleOver30
  35.                 .OrderBy(pair => pair.Key)
  36.                 .ToDictionary(pair => pair.Key, pair => pair.Value);
  37.  
  38.             //peopleOver30.Select(pair => $"{pair.Key} - {pair.Value}").ToList().ForEach(Console.WriteLine);
  39.            
  40.             foreach (var pair in peopleOver30)
  41.             {
  42.                 Console.WriteLine(pair.Key + " - " + pair.Value);
  43.             }
  44.  
  45.  
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement