Advertisement
lewapkon

Pola Prostokątów

Apr 3rd, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import java.awt.Rectangle;
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5.  
  6. /*
  7.  * http://pl.spoj.com/problems/SIL/
  8.  * SIL
  9.  * Pola Prostokątów
  10.  */
  11.  
  12. class SIL {
  13.     public static void main(String[] args) throws IOException {
  14.         BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  15.         String[] rect1 = in.readLine().split(" ");
  16.         String[] rect2 = in.readLine().split(" ");
  17.  
  18.         Rectangle a = new Rectangle(Integer.parseInt(rect1[0]),
  19.                         Integer.parseInt(rect1[3]),
  20.                         Math.abs(Integer.parseInt(rect1[2]) - Integer.parseInt(rect1[0])),
  21.                         Math.abs(Integer.parseInt(rect1[1]) - Integer.parseInt(rect1[3])));
  22.         Rectangle b = new Rectangle(Integer.parseInt(rect2[0]),
  23.                         Integer.parseInt(rect2[3]),
  24.                         Math.abs(Integer.parseInt(rect2[2]) - Integer.parseInt(rect2[0])),
  25.                         Math.abs(Integer.parseInt(rect2[1]) - Integer.parseInt(rect2[3])));
  26.         Rectangle c = a.intersection(b);
  27.  
  28.         int areaA = a.height * a.width;
  29.         int areaB = b.height * b.width;
  30.         int areaC = c.isEmpty() ? 0 : c.width * c.height;
  31.  
  32.         System.out.println(areaA + areaB - areaC);
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement