## Monday, 6 November 2017

### HackerRank Solution For Day 28: RegEx, Patterns, And Intro to Databases

Problem:- hackerRank-30-Days-of-Code/Day-28-RegEx-Pattern or Hackerrank, 30 Days of Code Challenges or Hackerrank 30 days of code Java Solution: Day 28 or HackerRank - Advance Your Coding Through Problem Solving or 30 Days of Code – Day 28: RegEx, Patterns, and Intro to Databases or C Language: HackerRank Day 28 Data Types 30 Day Solution In C or Day 28: RegEx, Patterns, and Intro to Databases or The 30 Days Regex Tutorial

Consider a database table, Emails, which has the attributes First Name and Email ID. Given N rows of data simulating the Emails table, print an alphabetically-ordered list of people whose email address ends in @gmail.com (RegEx Pattern)

Sample Input

6
riya riya@gmail.com
julia julia@julia.me
julia sjulia@gmail.com
julia julia@gmail.com
samantha samantha@gmail.com

Sample Output

ghanendra
julia
julia
riya
samantha

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.

Explanation:- RegEx, Patterns, and Intro to Databases Solution is same as SQL Query. First, we have database table consist first name and email Now we have to print the name of the person whose email ID ends with @gmail.com. So first step is to take a regular expression in like this "regex exp(".+@gmail\\.com\$");" and now with the help of sting array we will take an input Fname and Eid and compare Eid with a regular expression If Eid is matched with a regular expression then we store name of the person in a String array. Now the last step is to print the string array in order.
For better explanation let's take an example of above Sample Input, here number 6 ( total number of input ) and a first name and Email ID. As you can see the first email is riya@gmail.com this is correct so store or push into a string array, now come to second Email ID julia@julia.me as we can see there is no matching with @gmail.com than ignore this name and Email ID same for next and next to next and continue all have passed the condition. Now next step is to print the First name in ascending order.

Solution:- Day 28: RegEx, Patterns, and Intro to Databases Solution

#include <bits/stdc++.h>
using namespace std;

int main()
{
int N, i;

cin >> N;

regex exp(".+@gmail\\.com\$");

vector<string> strarray;

for(i = 0; i < N; i++)
{
string Fname;

string Eid;

cin >> Fname >> Eid;

if(regex_match(Eid, exp))
{
strarray.push_back(Fname);
}
}

sort(strarray.begin(), strarray.end());

for(i = 0; i < strarray.size();i++)
{
cout << strarray[i] << endl;
}

return 0;
}

Output:-

### You May Also See

1. Day 24: More Linked Lists

2. Day 25: Running Time and Complexity

3. Day 26: Nested Logic

4. Day 27: Testing

5. Day 29: Bitwise AND