Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. package examen2;
  2.  
  3. import java.io.*;
  4. import java.util.*;
  5.  
  6. public class Examen2 {
  7.  
  8. public static void main(String[] args) throws Exception {
  9. FileInputStream fis = new FileInputStream("dataIn.txt");
  10. BufferedReader br = new BufferedReader(new InputStreamReader(fis));
  11.  
  12. TreeSet<Punct> set = new TreeSet();
  13. String line;
  14.  
  15. //problem in the while statement
  16.  
  17. while (((line = br.readLine()).length() != 0)) {
  18. String[] splited = line.split("([^0-9\n\r\-][^0-9\n\r\-]*)");
  19. int[] number = new int[splited.length];
  20.  
  21. for (int i=0, j=0; i<splited.length; i++) {
  22. number[j] = Integer.parseInt(splited[i]);
  23. j++;
  24. }
  25.  
  26. set.add(new Punct(number[0], number[1]));
  27.  
  28. Iterator it = set.iterator();
  29.  
  30. while (it.hasNext()) {
  31. System.out.print(it.next());
  32. }
  33. System.out.println();
  34. }
  35.  
  36. br.close();
  37. br = null;
  38. fis = null;
  39. }
  40.  
  41. static class Punct implements Comparable {
  42.  
  43. int x;
  44. int y;
  45.  
  46. Punct() {
  47. x = 0;
  48. y = 0;
  49. }
  50. Punct(int x, int y) {
  51. this.x = x;
  52. this.y = y;
  53. }
  54.  
  55. @Override
  56. public String toString() {
  57. return "(" + this.x + ":" + this.y + ")";
  58. }
  59. @Override
  60. public boolean equals(Object o) {
  61. try {
  62. Punct other = (Punct)o;
  63. return (this.x==other.x && this.y==other.y);
  64. } catch (Exception ex) {
  65. System.out.println(ex.getMessage());
  66. }
  67. return false;
  68. }
  69. @Override
  70. public int compareTo(Object t) {
  71. Punct other = (Punct)t;
  72. if (this.x == other.x && this.y == other.y) {
  73. return 0;
  74. } else if (Math.sqrt(Math.pow(this.x, 2)+Math.pow(this.y, 2))-Math.sqrt(Math.pow(other.x, 2)+Math.pow(other.y, 2))>0) {
  75. return 1;
  76. } else {
  77. return -1;
  78. }
  79. }
  80.  
  81. @Override
  82. public int hashCode() {
  83. return super.hashCode(); //To change body of generated methods, choose Tools | Templates.
  84. }
  85. @Override
  86. protected void finalize() throws Throwable {
  87. super.finalize(); //To change body of generated methods, choose Tools | Templates.
  88. }
  89. @Override
  90. protected Object clone() throws CloneNotSupportedException {
  91. return super.clone(); //To change body of generated methods, choose Tools | Templates.
  92. }
  93.  
  94. }
  95.  
  96. }
  97.  
  98. at examen2.Examen2.main(Examen2.java:15)
  99.  
  100. while (((line = br.readLine()).length() != 0)) {
  101.  
  102. while((line=br.readLine())!=null) {
  103. //....
  104. }
  105.  
  106. while (((line = br.readLine()).length() != 0)) {
  107.  
  108. while ((line = br.readLine() != null) {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement