SHARE
TWEET

SoftUni/C#Advanced/WeakStudents

a guest Apr 7th, 2017 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. public class Startup
  9. {
  10.     public static void Main()
  11.     {
  12.         string input = Console.ReadLine();
  13.         List<Student> students = new List<Student>();
  14.         List<double> studentMarks = new List<double>();
  15.  
  16.         string saveMarks = string.Empty;
  17.         string saveNames = string.Empty;
  18.  
  19.         while (!input.Contains("END"))
  20.         {
  21.             string patternName = @"([a-zA-Z]+\s[a-zA-Z]+)";// take only digits separated by empty space
  22.             string patternMarks = @"\s([\d\s]+)"; // take the words
  23.  
  24.             Regex regexMark = new Regex(patternMarks);
  25.             Regex regexName = new Regex(patternName);
  26.  
  27.             MatchCollection matchCollection = regexMark.Matches(input);
  28.             MatchCollection matchCollection2 = regexName.Matches(input);
  29.  
  30.             foreach (Match match in matchCollection)
  31.             {
  32.                 saveMarks = ((match.Groups[1].ToString()));
  33.             }
  34.  
  35.             foreach (Match match in matchCollection2)
  36.             {
  37.                 saveNames = ((match.Groups[1].ToString()));
  38.             }
  39.  
  40.             studentMarks.AddRange(saveMarks.Split().Select(double.Parse).ToList());
  41.  
  42.             string[] splitInput = saveNames.Split();
  43.             string fName = splitInput[0];
  44.             string lName = splitInput[1];
  45.  
  46.             students.Add(new Student(fName, lName, studentMarks));
  47.  
  48.             studentMarks.Clear();
  49.             input = Console.ReadLine();
  50.         }
  51.  
  52.         foreach (var student in students.Where(x => x.Marks.Any(y => y == 3) && x.Marks.Any(y => y < 3)))
  53.         {
  54.             Console.WriteLine($"{student.FirstName} {student.LastName}");
  55.         }
  56.     }
  57. }
  58.  
  59. public class Student
  60. {
  61.     public string FirstName { get; set; }
  62.  
  63.     public string LastName { get; set; }
  64.  
  65.     public List<double> Marks { get; set; } = new List<double>();
  66.  
  67.     public Student(string fName, string lName, List<double> marks)
  68.     {
  69.         this.FirstName = fName;
  70.         this.LastName = lName;
  71.         Marks.AddRange(marks);
  72.     }
  73. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top