static void Main() { List <Student> students = new List <Student>(); List <StudentSpecialty> studentSpecialties = new List <StudentSpecialty>(); string[] input = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();; while (input[0] != "Students:") { var speciality = new StudentSpecialty(input[0] + " " + input[1], input[2]); studentSpecialties.Add(speciality); input = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); } input = Console.ReadLine().Split(' ').ToArray(); while (input[0] != "END") { var student = new Student(input[1] + " " + input[2], input[0]); students.Add(student); input = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); } var studentsNameFacultyNumberSpecialName = studentSpecialties.Join(students, sp => sp.FacultyNumber, st => st.FacultyNumber, (sp, st) => new { st.Name, sp.FacultyNumber, sp.Specialty } ).OrderBy(res => res.Name).ToList(); foreach (var studentsFaculty in studentsNameFacultyNumberSpecialName) { Console.WriteLine(studentsFaculty.Name + " " + studentsFaculty.FacultyNumber + " " + studentsFaculty.Specialty); } }
public static void Main(string[] args) { string input = Console.ReadLine(); List <Student> students = new List <Student>(); List <StudentSpecialty> specialities = new List <StudentSpecialty>(); while (input != "Students:") { var tokens = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(); StudentSpecialty speciality = new StudentSpecialty(); speciality.SpecialityName = tokens[0] + " " + tokens[1]; speciality.FacNumber = int.Parse(tokens[2]); specialities.Add(speciality); input = Console.ReadLine(); } input = Console.ReadLine(); while (input != "END") { var tokens = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(); Student student = new Student(); student.FacNumber = int.Parse(tokens[0]); student.StudentName = tokens[1] + " " + tokens[2]; students.Add(student); input = Console.ReadLine(); } var groupedStudents = from s in students.OrderBy(s => s.StudentName) join sp in specialities on s.FacNumber equals sp.FacNumber select new { s.StudentName, s.FacNumber, sp.SpecialityName }; foreach (var student in groupedStudents) { Console.WriteLine($"{student.StudentName} {student.FacNumber} {student.SpecialityName}"); } }
public static void Main() { string input = Console.ReadLine(); var specialityList = new List <StudentSpecialty>(); var students = new List <Student>(); while (!input.Equals("Students:")) { var tokens = input.Split(); var speciality = tokens[0] + " " + tokens[1]; var facultyNumber = tokens[2]; var currentStudent = new StudentSpecialty(speciality, facultyNumber); specialityList.Add(currentStudent); input = Console.ReadLine(); } input = Console.ReadLine(); while (!input.Equals("END")) { var tokens = input.Split(); var studentName = tokens[1] + " " + tokens[2]; var facultyNumber = tokens[0]; var currentStudent = new Student(facultyNumber, studentName); students.Add(currentStudent); input = Console.ReadLine(); } var result = students.Join(specialityList, st => st.FacultyNumber, sp => sp.FacultyNumber, (st, sp) => new { st.StudentsName, st.FacultyNumber, sp.Specialty }); foreach (var item in result.OrderBy(x => x.StudentsName)) { Console.WriteLine($"{item.StudentsName} {item.FacultyNumber} {item.Specialty}"); } }
static void P12() { Console.WriteLine(new string('-', 30)); Console.WriteLine("Problem 12: Students Joined to Specialties:"); Console.WriteLine(new string('-', 30)); List<StudentSpecialty> specialties = new List<StudentSpecialty>(); StudentSpecialty studSpec01 = new StudentSpecialty(); studSpec01.FacultyNumber = "123414"; studSpec01.Specialty = "Web Developer"; specialties.Add(studSpec01); StudentSpecialty studSpec02 = new StudentSpecialty(); studSpec02.FacultyNumber = "123656"; studSpec02.Specialty = "C# Developer"; specialties.Add(studSpec02); StudentSpecialty studSpec03 = new StudentSpecialty(); studSpec03.FacultyNumber = "129813"; studSpec03.Specialty = "Java Developer"; specialties.Add(studSpec03); StudentSpecialty studSpec04 = new StudentSpecialty(); studSpec04.FacultyNumber = "111814"; studSpec04.Specialty = "Web Developer"; specialties.Add(studSpec04); StudentSpecialty studSpec05 = new StudentSpecialty(); studSpec05.FacultyNumber = "125536"; studSpec05.Specialty = "Java Developer"; specialties.Add(studSpec05); StudentSpecialty studSpec06 = new StudentSpecialty(); studSpec06.FacultyNumber = "122214"; studSpec06.Specialty = "JavaScript Developer"; specialties.Add(studSpec06); StudentSpecialty studSpec07 = new StudentSpecialty(); studSpec07.FacultyNumber = "111113"; studSpec07.Specialty = "C# Developer"; specialties.Add(studSpec07); StudentSpecialty studSpec08 = new StudentSpecialty(); studSpec08.FacultyNumber = "121116"; studSpec08.Specialty = "C# Developer"; specialties.Add(studSpec08); StudentSpecialty studSpec09 = new StudentSpecialty(); studSpec09.FacultyNumber = "113314"; studSpec09.Specialty = "JavaScript Developer"; specialties.Add(studSpec09); StudentSpecialty studSpec10 = new StudentSpecialty(); studSpec10.FacultyNumber = "110156"; studSpec10.Specialty = "Web Developer"; specialties.Add(studSpec10); Console.WriteLine("{0, -20}| Faculty Number | Specialty", "Student"); Console.WriteLine(new string('-',60)); var studentsBySpecialty = from student in studentsList join spec in specialties on student.FacultyNumber equals spec.FacultyNumber select new { FullName = string.Format("{0} {1}", student.FirstName, student.LastName), FacultyNum = student.FacultyNumber, Specialty = spec.Specialty }; foreach (var student in studentsBySpecialty) { Console.WriteLine("{0, -20}| F#:{1} | Specialty: {2}", student.FullName, student.FacultyNum, student.Specialty); } }
static void Main() { List <Student> students = new List <Student>() { new Student("Mihail", "Nikolov", 19, "245121493", "+359-978-6458", new List <int>() { 6, 6, 6, 6 }, 4, "*****@*****.**", "Beginner"), new Student("Ivan", "Petrov", 23, "245121457", "+359-878-7965", new List <int>() { 3, 5, 4, 5 }, 3, "*****@*****.**", "Senior"), new Student("Ivan", "Ivanov", 23, "245121572", "+359-878-7965", new List <int>() { 3, 5, 4, 5 }, 3, "*****@*****.**", "Ninja"), new Student("Radoslav", "Hokov", 25, "245121523", "02-897-7895", new List <int>() { 4, 3, 5, 6 }, 2, "*****@*****.**", "Ninja"), new Student("Petar", "Ivanov", 32, "245121585", "+359-787-9756", new List <int>() { 6, 3, 5, 6 }, 1, "*****@*****.**", "Beginner"), new Student("Nikola", "Benkov", 27, "245121405", "+3592-888-7389", new List <int>() { 5, 5, 4, 5 }, 3, "*****@*****.**", "Ninja"), new Student("Svetoslav", "Gavadinov", 20, "245121511", "+359-875-5468", new List <int>() { 2, 3, 2, 4 }, 4, "*****@*****.**", "Senior") }; // Problem 4. Students by Group var orderedStudentsByFirstName = from student in students orderby student.FirstName select student; PrintStudents(orderedStudentsByFirstName); Console.WriteLine("\n\n"); // Problem 5. Students by First and Last Name var orderedStudentsByFirstAndLastName = from student in students orderby student.FirstName, student.LastName select student; PrintStudents(orderedStudentsByFirstAndLastName); Console.WriteLine("\n\n"); // Problem 6. Students by Age var orderedStudentsByAge = from student in students orderby student.Age select student; PrintStudents(orderedStudentsByAge); Console.WriteLine("\n\n"); // Problem 7. Sort Students var orderedStudentsLambdaFirstAndLastName = students.OrderByDescending(student => student.FirstName).ThenByDescending(student => student.LastName); PrintStudents(orderedStudentsLambdaFirstAndLastName); Console.WriteLine("\n\n"); // Problem 8. Filter Students by Email Domain var orderedStudentsByEmail = from student in students where student.Email.Contains("@abv.bg") select student; PrintStudents(orderedStudentsByEmail); Console.WriteLine("\n\n"); // Problem 9. Filter Students by Phone var orderedStudentsByPhone = from student in students where student.Phone.StartsWith("02") || student.Phone.StartsWith("+3592") || student.Phone.StartsWith("+359 2") select student; PrintStudents(orderedStudentsByPhone); Console.WriteLine("\n\n"); // Problem 10. Excellent Students var orderedStudentsByExcellentMark = from student in students where student.Marks.Contains(6) select new { FirstName = student.FirstName, Marks = student.Marks }; foreach (var student in orderedStudentsByExcellentMark) { string marks = string.Join(", ", student.Marks); Console.WriteLine("{0}: ({1})", student.FirstName, marks); } Console.WriteLine("\n\n"); // Problem 11. Weak Students var orderedStudentsByWeakMark = from student in students where student.Marks.Where(mark => mark == 2).Count() == 2 select student; PrintStudents(orderedStudentsByWeakMark); Console.WriteLine("\n\n"); // Problem 12. Students Enrolled in 2014 var orderedStudentsEnrolledIn2014 = students.Where(student => student.FacultyNumber.ToString().Substring(5, 2) == "14"); PrintStudents(orderedStudentsEnrolledIn2014); Console.WriteLine("\n\n"); // Problem 12.* Students by Group var groups = from student in students group student by student.GroupName into g orderby g.Key select g; foreach (var item in groups) { Console.WriteLine("\n{0}:", item.Key); var tempStudents = students.Where(s => s.GroupName == item.Key); foreach (var student in tempStudents) { Console.WriteLine(student); } } Console.WriteLine("\n\n"); // Problem 13.* Students Joined to Specialties StudentSpecialty Mihail = new StudentSpecialty("Software Enginering", "245121493"); StudentSpecialty Ivan = new StudentSpecialty("QA", "245121457"); List <StudentSpecialty> specialties = new List <StudentSpecialty>(); specialties.Add(Mihail); specialties.Add(Ivan); var studentsWithSpecialties = from speciality in specialties join student in students on speciality.FacultyNumber equals student.FacultyNumber select new { student, FacultyName = speciality.SpecialityName }; foreach (var item in studentsWithSpecialties) { Console.WriteLine(item); } }