Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- namespace Objects_and_Classes
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<Student> students = new List<Student>();
- string input = Console.ReadLine();
- while (input != "end")
- {
- string[] tokens = input.Split(" ");
- string firstName = tokens[0];
- string lastName = tokens[1];
- int age = int.Parse(tokens[2]);
- string city = tokens[3];
- if (students.Count > 0)
- {
- for (int i = 0; i < students.Count; i++)
- {
- if (firstName == students[i].FirstName && lastName == students[i].LastName)
- {
- students[students.Count - 1].Age = age;
- students[students.Count - 1].Hometown = city;
- }
- else
- {
- Student student = new Student();
- student.FirstName = firstName;
- student.LastName = lastName;
- student.Age = age;
- student.Hometown = city;
- students.Add(student);
- input = Console.ReadLine();
- break;
- }
- }
- }
- input = Console.ReadLine();
- }
- string cityEnd = Console.ReadLine();
- foreach (Student student in students)
- {
- if (cityEnd == student.Hometown)
- {
- Console.WriteLine($"{student.FirstName} {student.LastName} is {student.Age} years old.");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement