Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. /**
  4. *
  5. * @author Usuario
  6. */
  7. public class P291 {
  8. Scanner in;
  9.  
  10. public boolean caso() {
  11. int numParrafos = Integer.parseInt(in.nextLine());
  12. if (numParrafos == 0) {
  13. return false;
  14. }
  15. Map<String, String> m = new TreeMap<>();
  16. for (int i = 1; i <= numParrafos; i++) {
  17. String parrafo = in.nextLine().toLowerCase();
  18. String[] a = parrafo.split(" ");
  19. for (int j = 0; j < a.length; j++) {
  20. if (a[j].length() > 2) {
  21. if (m.containsKey(a[j]) ) {
  22. if (!m.get(a[j]).equals("" + i)) {
  23. String lineas = m.get(a[j]) + " " + i;
  24. m.put(a[j], lineas);
  25. }
  26.  
  27. } else {
  28. m.put(a[j], "" + i);
  29. }
  30. }
  31. }
  32. }
  33. for (String p : m.keySet()) {
  34. System.out.format("%s %s%n", p, m.get(p));
  35. }
  36. System.out.println("---");
  37. return true;
  38. }
  39.  
  40. public void run() {
  41. in = new Scanner(System.in);
  42. while (caso());
  43. }
  44.  
  45. public static void main(String[] args) {
  46. // TODO code application logic here
  47. new P291().run();
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement