qwerty787788

asteroids.java

Aug 6th, 2016
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.util.Scanner;
  4.  
  5. // Sample input 3, in Java.
  6. public class asteroids {
  7.     public asteroids() {
  8.     }
  9.  
  10.     static int n = -1, m = -1;
  11.  
  12.     static void load() {
  13.         if (n != -1) {
  14.             return;
  15.         }
  16.         Scanner sc;
  17.         try {
  18.             sc = new Scanner(new File("input.txt"));
  19.  
  20.             n = sc.nextInt();
  21.             m = sc.nextInt();
  22.             s = new String[n];
  23.             for (int i = 0; i < n; i++) {
  24.                 s[i] = sc.next();
  25.             }
  26.         } catch (FileNotFoundException e) {
  27.             // TODO Auto-generated catch block
  28.             e.printStackTrace();
  29.         }
  30.     }
  31.  
  32.     static String[] s;
  33.  
  34.     public static long GetHeight() {
  35.         load();
  36.         return n;
  37.     }
  38.  
  39.     public static long GetWidth() {
  40.         load();
  41.         return m;
  42.     }
  43.  
  44.     public static char GetPosition(long i, long j) {
  45.         load();
  46.         if (i < 0 || i >= n || j < 0 || j >= m)
  47.             throw new IllegalArgumentException("Invalid argument");
  48.         return s[(int) i].charAt((int) j);
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment