Day 28: RegEx, Patterns, and Intro to Databases In Java | 30 Days Of Code | Hackerrank Programming Solutions

Hello Programmers/Coders, Today we are going to share solutions of Programming problems of 30 Days Of Code, HackerRank. At Each Problem with Successful submission with all Test Cases Passed, you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight your profile to the recruiters.

In this post, you will find the solution for Day 28: RegEx, Patterns, and Intro to Databases in Java-HackerRank Problem. We are providing the correct and tested solutions of coding problems present on HackerRank. If you are not able to solve any problem, then you can take help from our Blog/website.

Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.

Link for the ProblemDay 28: RegEx, Patterns, and Intro to Databases – Hacker Rank Solution

Day 28: RegEx, Patterns, and Intro to Databases – Hacker Rank Solution

Problem:

Objective
Today, we’re working with regular expressions. Check out the Tutorial tab for learning materials and an instructional video!

Task
Consider a database table, Emails, which has the attributes First Name and Email ID. Given  rows of data simulating the Emails table, print an alphabetically-ordered list of people whose email address ends in .

Input Format

The first line contains an integer, , total number of rows in the table.
Each of the  subsequent lines contains  space-separated strings denoting a person’s first name and email ID, respectively.

Constraints

  • Each of the first names consists of lower case letters  only.
  • Each of the email IDs consists of lower case letters ,  and  only.
  • The length of the first name is no longer than 20.
  • The length of the email ID is no longer than 50.

Output Format

Print an alphabetically-ordered list of first names for every user with a gmail account. Each name must be printed on a new line.

Sample Input

6
riya [email protected]
julia [email protected]
julia [email protected]
julia [email protected]
samantha [email protected]
tanya [email protected]

Sample Output

julia
julia
riya
samantha
tanya
Day 28: RegEx, Patterns, and Intro to Databases – Hacker Rank Solution
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class Day28RegExPatternsAndIntroToDatabases {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		List list = new ArrayList();
		for (int a0 = 0; a0 [email protected]";

			Pattern p = Pattern.compile(regExPattern);
			Matcher m = p.matcher(emailID);
			if (m.find()) {
				list.add(firstName);
			}

		}
		Collections.sort(list);
		for (String string : list) {
			System.out.println(string);
		}
		in.close();
	}
}

Leave a Comment

Scroll to Top