Advertisement
Guest User

Untitled

a guest
Oct 19th, 2016
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. /*
  2. Task
  3. 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 .
  4.  
  5. Input Format
  6.  
  7. The first line contains an integer, , total number of rows in the table.
  8. Each of the subsequent lines contains space-separated strings denoting a person's first name and email ID, respectively.
  9.  
  10.  
  11. Sample Input
  12.  
  13. 6
  14. riya riya@gmail.com
  15. julia julia@julia.me
  16. julia sjulia@gmail.com
  17. julia julia@gmail.com
  18. samantha samantha@gmail.com
  19. tanya tanya@gmail.com
  20. Sample Output
  21.  
  22. julia
  23. julia
  24. riya
  25. samantha
  26. tanya
  27.  
  28.  
  29. */
  30. import java.io.*;
  31. import java.util.*;
  32. import java.text.*;
  33. import java.math.*;
  34. import java.util.regex.*;
  35.  
  36. public class Solution {
  37.  
  38. public static void main(String[] args) {
  39. Scanner in = new Scanner(System.in);
  40. int N = in.nextInt();
  41. String[] str=new String[N];
  42.  
  43. int i=0;
  44. Pattern p = Pattern.compile("[a-z]+@gmail.com");
  45. ArrayList<String> arr=new ArrayList();
  46. Matcher m;
  47. for(int a0 = 0; a0 < N; a0++)
  48. {
  49. String firstName = in.next();
  50. String emailID = in.next();
  51. m=p.matcher(emailID);
  52. if(m.find())
  53. arr.add(firstName.toLowerCase());
  54. }
  55. Collections.sort(arr);
  56.  
  57. for(String s:arr)
  58. {
  59. System.out.println(s);
  60.  
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement