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 Courses
- {
- public class Course
- {
- public string Courses { get; set; }
- public int People { get; set; }
- public List<string> Students { get; set; }
- public Course(string courses)
- {
- this.Courses = courses;
- this.People = 1;
- this.Students = new List<string>();
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- List<Course> CoursesAndStudents = new List<Course>();
- while (true)
- {
- List<string> information = Console.ReadLine()
- .Split(new[] { " : " }, StringSplitOptions.RemoveEmptyEntries)
- .ToList();
- string courses = information[0];
- if (courses == "end")
- {
- break;
- }
- string person = information[1];
- bool isExist = CoursesAndStudents
- .Any(x => x.Courses.Contains(courses));
- Course addingStudents = new Course(courses);
- if (!isExist)
- {
- CoursesAndStudents.Add(addingStudents);
- int index = CoursesAndStudents.FindIndex(x => x.Courses == courses);
- CoursesAndStudents[index].Students.Add(person);
- }
- else
- {
- int index = CoursesAndStudents.FindIndex(x => x.Courses == courses);
- CoursesAndStudents[index].Students.Add(person);
- CoursesAndStudents[index].People++;
- }
- }
- var SortedCoursesAndStudents = CoursesAndStudents
- .OrderByDescending(x => x.People);
- foreach (var kvp in SortedCoursesAndStudents)
- {
- Console.WriteLine($"{kvp.Courses}: {kvp.People}");
- foreach (var student in kvp.Students.OrderBy(x => x))
- {
- Console.WriteLine($"-- {student}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement