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;
- namespace Demo
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- List<Person> people = new List<Person>();
- for (int i = 1; i <= n; i++)
- {
- string input = Console.ReadLine();
- string name = input.Split(" ")[0];
- int age = int.Parse(input.Split(" ")[1]);
- Person person = new Person(name, age);
- people.Add(person);
- }
- Dictionary<string, int> peopleOver30 = new Dictionary<string, int>();
- foreach(Person person in people)
- {
- if(person.Age > 30)
- {
- peopleOver30.Add(person.Name, person.Age);
- }
- }
- peopleOver30 = peopleOver30
- .OrderBy(pair => pair.Key)
- .ToDictionary(pair => pair.Key, pair => pair.Value);
- //peopleOver30.Select(pair => $"{pair.Key} - {pair.Value}").ToList().ForEach(Console.WriteLine);
- foreach (var pair in peopleOver30)
- {
- Console.WriteLine(pair.Key + " - " + pair.Value);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement