Day 28: RegEx, Patterns, and Intro to Databases

  • + 0 comments

    In C#

    class Solution
    {
        public static void Main(string[] args)
        {
            int N = Convert.ToInt32(Console.ReadLine().Trim());
            List<string> names = new List<string>();
    
            for (int NItr = 0; NItr < N; NItr++)
            {
                string[] firstMultipleInput = Console.ReadLine().TrimEnd().Split(' ');
    
                string firstName = firstMultipleInput[0];
    
                string emailID = firstMultipleInput[1];
                
                var regex = new Regex("[A-Za-z._]+@gmail.com");
                if(regex.IsMatch(emailID))
                {
                    names.Add(firstName);
                }
            }
            
            names.Sort();
            names.ForEach(n => Console.WriteLine(n));
        }
    }