You are viewing a single comment's thread. Return to all comments →
Java
public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(bufferedReader.readLine().trim()); String p = "\\w*@gmail.com\\b"; Pattern pattern = Pattern.compile(p); ArrayList<String> t = new ArrayList<>(); IntStream.range(0, N).forEach(NItr -> { try { String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" "); String firstName = firstMultipleInput[0]; String emailID = firstMultipleInput[1]; Matcher m = pattern.matcher(emailID); if(m.find()) { t.add(firstName); } } catch (IOException ex) { throw new RuntimeException(ex); } }); t.sort(Comparator.naturalOrder()); t.forEach(System.out::println); 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 →
Java