Day 28: RegEx, Patterns, and Intro to Databases
For Explanation Check Video:
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
Code:
import java.io.*;import java.math.*;import java.security.*;import java.text.*;import java.util.*;import java.util.concurrent.*;import java.util.regex.*;
public class Solution {
private static final Scanner scanner = new Scanner(System.in);
public static void main(String[] args) { int N = scanner.nextInt(); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); String reg = ".+@gmail\\.com$"; Pattern p = Pattern.compile(reg); ArrayList<String> al = new ArrayList<>(); for (int NItr = 0; NItr < N; NItr++) { String[] firstNameEmailID = scanner.nextLine().split(" ");
String firstName = firstNameEmailID[0];
String emailID = firstNameEmailID[1]; Matcher m = p.matcher(emailID); if(m.find()){ al.add(firstName); } } Collections.sort(al); for(String s:al){ System.out.println(s); } scanner.close(); }}
Comments
Post a Comment