예제 #1
0
        public static void Main()
        {
            List <StudentSpecialty> specialties = new List <StudentSpecialty>();
            List <Student>          students    = new List <Student>();

            string input = Console.ReadLine();

            while (input != "Students:")
            {
                string[] specialtyArgs  = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                string   speacialtyName = specialtyArgs[0] + " " + specialtyArgs[1];
                string   facultyNumber  = specialtyArgs[2];

                StudentSpecialty speacialty = new StudentSpecialty(speacialtyName, facultyNumber);
                specialties.Add(speacialty);

                input = Console.ReadLine();
            }

            input = Console.ReadLine();
            while (input != "END")
            {
                string[] studentArgs   = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                string   facultyNumber = studentArgs[0];
                string   fistName      = studentArgs[1];
                string   lastName      = studentArgs[2];

                Student student = new Student(fistName, lastName, facultyNumber);
                students.Add(student);

                input = Console.ReadLine();
            }

            var result = specialties.Join(
                students,
                ss => ss.FacultyNumber,
                st => st.FacultyNumber,
                (ss, st) => new
            {
                SpecialtyName = ss.SpeacialtyName,
                StudentName   = st.FullName,
                FacultyNumber = st.FacultyNumber
            });

            foreach (var item in result.OrderBy(x => x.StudentName))
            {
                Console.WriteLine($"{item.StudentName} {item.FacultyNumber} {item.SpecialtyName}");
            }
        }
예제 #2
0
        public static void Main()
        {
            var inputSpecialty = Console.ReadLine();

            var specialtyList = new List <StudentSpecialty>();
            var studentList   = new List <Student>();

            while (inputSpecialty != "Students:")
            {
                var tokensSpecialty = inputSpecialty.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var name            = $"{tokensSpecialty[0].Trim()} {tokensSpecialty[1].Trim()}";
                var facultyNumber   = tokensSpecialty[2].Trim();

                var currentSpecialty = new StudentSpecialty(name, facultyNumber);
                specialtyList.Add(currentSpecialty);

                inputSpecialty = Console.ReadLine();
            }

            var inputStudent = Console.ReadLine();

            while (inputStudent != "END")
            {
                var tokensStudent  = inputStudent.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var facultyNumber  = tokensStudent[0].Trim();
                var name           = $"{tokensStudent[1].Trim()} {tokensStudent[2].Trim()}";
                var currentStudent = new Student(name, facultyNumber);
                studentList.Add(currentStudent);

                inputStudent = Console.ReadLine();
            }

            var joined = specialtyList
                         .Join(studentList, sp => sp.FacultyNumber, st => st.FacultyNumber, (sp, st) => new
            {
                Name          = st.Name,
                FacultyNumber = st.FacultyNumber,
                Specialty     = sp.Name
            })
                         .ToList();

            foreach (var student in joined.OrderBy(s => s.Name))
            {
                Console.WriteLine($"{student.Name} {student.FacultyNumber} {student.Specialty}");
            }
        }