Ejemplo n.º 1
0
        public static void Main()
        {
            var input = Console.ReadLine();
            List <StudentSpecialty> studentSpecialties = new List <StudentSpecialty>();

            while (!input.Equals("Students:"))
            {
                var specialtyInfo = input.Split();

                StudentSpecialty studentSpecialty = new StudentSpecialty()
                {
                    SpecialtyName = specialtyInfo[0] + " " + specialtyInfo[1],
                    FacultyNumber = int.Parse(specialtyInfo[2])
                };

                studentSpecialties.Add(studentSpecialty);
                input = Console.ReadLine();
            }

            input = Console.ReadLine();

            List <Student> students = new List <Student>();

            while (!input.Equals("END"))
            {
                var studentInfo = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                Student student = new Student()
                {
                    FacultyNumber = int.Parse(studentInfo[0]),
                    StudentName   = studentInfo[1] + " " + studentInfo[2]
                };

                students.Add(student);
                input = Console.ReadLine();
            }

            var matchedStudents = studentSpecialties
                                  .Join(students,
                                        fac => fac.FacultyNumber,
                                        st => st.FacultyNumber,
                                        (fac, st) => new
            {
                StudentName   = st.StudentName,
                SpecialtyName = fac.SpecialtyName,
                FacultyNumber = fac.FacultyNumber
            })
                                  .OrderBy(x => x.StudentName);

            foreach (var match in matchedStudents)
            {
                Console.WriteLine($"{match.StudentName} {match.FacultyNumber} {match.SpecialtyName}");
            }
        }
        public static void Main()
        {
            var studentSpecialtyInfo = Console.ReadLine().Split();
            var StudentSpecialties   = new List <StudentSpecialty>();

            while (studentSpecialtyInfo[0] != "Students:")
            {
                var studentSpecialty = new StudentSpecialty
                {
                    SpecialtyName = String.Concat(studentSpecialtyInfo[0], " ", studentSpecialtyInfo[1]),
                    FacultyNumber = studentSpecialtyInfo[2]
                };

                StudentSpecialties.Add(studentSpecialty);

                studentSpecialtyInfo = Console.ReadLine().Split();
            }

            var studentInfo = Console.ReadLine().Split();
            var students    = new List <Student>();

            while (studentInfo[0] != "END")
            {
                var student = new Student
                {
                    FacultyNumber = studentInfo[0],
                    Name          = string.Concat(studentInfo[1], " ", studentInfo[2])
                };

                students.Add(student);

                studentInfo = Console.ReadLine().Split();
            }

            var joinedTable = students.Join(StudentSpecialties,
                                            stud => stud.FacultyNumber,
                                            spec => spec.FacultyNumber,
                                            (stud, spec) => new { stud.Name, stud.FacultyNumber, spec.SpecialtyName })
                              .ToList();

            foreach (var entry in joinedTable.OrderBy(x => x.Name))
            {
                Console.WriteLine($"{entry.Name} {entry.FacultyNumber} {entry.SpecialtyName}");
            }
        }