Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Scanner;
- // Sample input 3, in Java.
- public class asteroids {
- public asteroids() {
- }
- static int n = -1, m = -1;
- static void load() {
- if (n != -1) {
- return;
- }
- Scanner sc;
- try {
- sc = new Scanner(new File("input.txt"));
- n = sc.nextInt();
- m = sc.nextInt();
- s = new String[n];
- for (int i = 0; i < n; i++) {
- s[i] = sc.next();
- }
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- static String[] s;
- public static long GetHeight() {
- load();
- return n;
- }
- public static long GetWidth() {
- load();
- return m;
- }
- public static char GetPosition(long i, long j) {
- load();
- if (i < 0 || i >= n || j < 0 || j >= m)
- throw new IllegalArgumentException("Invalid argument");
- return s[(int) i].charAt((int) j);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment