Advertisement
_CodeBehind

02

Jun 16th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. public class StudentsByFirstAndLastName
  6. {
  7.     public static void Main()
  8.     {
  9.         string input;
  10.  
  11.         var students = new List<string>();
  12.  
  13.         while ((input = Console.ReadLine()) != "END")
  14.         {
  15.             var tokens = input
  16.                 .Split();
  17.  
  18.             students.Add($"{tokens[0]} {tokens[1]}");
  19.         }
  20.  
  21.         var result = students
  22.             .Select(s =>
  23.             {
  24.                 var tokens = s.Split();
  25.                 var firstName = tokens[0];
  26.                 var secondName = tokens[1];
  27.                 return new { firstName, secondName };
  28.             })
  29.             .Where(x => x.firstName.CompareTo(x.secondName) == -1)
  30.             .ToList();
  31.  
  32.         foreach (var st in result)
  33.         {
  34.             Console.WriteLine($"{st.firstName} {st.secondName}");
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement