You are viewing a single comment's thread. Return to all comments →
import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.function.*; import java.util.regex.*; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(bufferedReader.readLine().trim()); String regex = "(?<gml>[\\w.]+@gmail.com)"; Pattern p = Pattern.compile(regex); Matcher m ; List<String> validUsers = new ArrayList(); IntStream.range(0, N).forEach(NItr -> { try { String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" "); String firstName = firstMultipleInput[0]; String emailID = firstMultipleInput[1]; if(emailID.matches(regex)) { validUsers.add(firstName); } } catch (IOException ex) { throw new RuntimeException(ex); } }); Collections.sort(validUsers); validUsers.stream().forEach((u) -> {System.out.println(u);}); bufferedReader.close(); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Day 28: RegEx, Patterns, and Intro to Databases
You are viewing a single comment's thread. Return to all comments →