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 riya@gmail.com
julia julia@julia.me
julia sjulia@gmail.com
julia julia@gmail.com
samantha samantha@gmail.com
tanya tanya@gmail.com

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<String> list = new ArrayList<String>();
		for (int a0 = 0; a0 < N; a0++) {
			String firstName = in.next();
			String emailID = in.next();
			String regExPattern = "[a-z].@gmail.com";

			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();
	}
}

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

Leave a Comment

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker๐Ÿ™.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock