Code:trickyotool
Code:100% of the proceeds from Givoogle, less operating costs, are donated to the American Cancer Society, an institution whose goals are aligned with our mission of spreading hope to those most in need.
Code:http://pandadan.files.wordpress.com/2007/04/funny_sport_photo_23.jpg
curious lol and that is going on my blogCode:http://pandadan.files.wordpress.com/2007/04/funny_sport_photo_23.jpg![]()
Code:A lot of spaces here Preserves Unix style line breaks? A lot of spaces here Preserves Unix style line breaks?
Code:package challenges; import java.io.*; import java.util.*; /* * These are just notes about what could be going wrong. * * I do bounds checking on every input based on the idea that the specs * do not say that the input will be in boundso the array. * This is BS. The specs say that an image will be an M x N image but the output * is given as an N x M image. * * The number of cols is given as M >= 1 so we cannot assume an upper bounds. * The number of rows is given as N <= 251, so we can assume an upper bounds on rows. * * The specs do not say the first command will be create a new image. So what do we * do if it not the first command? * * The specs do not state that X and Y will always be in bounds of the array. * The specs do not say that X and Y are in the set of reals. WTF? This is a bit extreme. * * The parameters defined as X, Y, X1, Y1, X2, Y2 are not in any defined order. * So X is not necessarily < Y * As such X1 might be > X2 and Y1 might be > Y2. So Math.min and Math.max should fix this * * The specs do not state that the color C will be one letter. It might be 2? * * @author James */ class Main { public static char[][] arcImage = new char[251][251]; public static int M, N; public static int[] DX = {1, 0, -1, 0}; public static int[] DY = {0, 1, 0, -1}; public static void main(String[] args) throws IOException { Scanner fin = new Scanner(new FileReader("graphical.txt")); //Scanner fin = new Scanner(System.in); String s; // the command to be executed char c; // the color to fill in while (fin.hasNext()) { s = fin.next(); if (s.equals("I")) { N = fin.nextInt(); M = fin.nextInt(); clear(); } else if (s.equals("C")) { clear(); } else if (s.equals("L")) { int y = fin.nextInt() - 1; int x = fin.nextInt() - 1; c = fin.next().charAt(0); if (boundsCheck(x, y)) { arcImage[x][y] = c; } } else if (s.equals("V")) { int x = fin.nextInt() - 1; // column int y1 = fin.nextInt() - 1; // row int y2 = fin.nextInt() - 1; // row c = fin.next().charAt(0); for (int y = Math.min(y1, y2); y <= Math.max(y1, y2); y++) { if (boundsCheck(x, y)) { arcImage[y][x] = c; } } } else if (s.equals("H")) { /* Columns x1-x2 inclusive*/ int x1 = fin.nextInt() - 1; int x2 = fin.nextInt() - 1; int y = fin.nextInt() - 1; c = fin.next().charAt(0); for (int x = Math.min(x1, x2); x <= Math.max(x1, x2); x++) { if (boundsCheck(y, x)) { arcImage[y][x] = c; } } } else if (s.equals("K")) { int x1 = fin.nextInt() - 1; int y1 = fin.nextInt() - 1; int x2 = fin.nextInt() - 1; int y2 = fin.nextInt() - 1; c = fin.next().charAt(0); for (int x = Math.min(x1, x2); x <= Math.max(x1, x2); x++) { for (int y = Math.min(y1, y2); y <= Math.max(y1, y2); y++) { if (boundsCheck(x, y)) { arcImage[x][y] = c; } } } } else if (s.equals("F")) { /* fill the region R with the color C, where R is defined as follows. Pixel (X,Y) belongs to R. Any other pixel which is the same color as pixel (X,Y) and shares a common side with any pixel in R also belongs to this region. Solution: A recursive flood fill */ int x = fin.nextInt() - 1; int y = fin.nextInt() - 1; char cReplace = arcImage[x][y]; c = fin.next().charAt(0); if (boundsCheck(x, y)) { fill(x, y, cReplace, c); } // } else if (s.equals("S")) { // display name and output the image String sName = fin.nextLine().trim(); System.out.println(sName); output(); } else if (s.equals("X")) { // kill program break; } } fin.close(); System.exit(0); } public static void clear() { for (int x = 0; x < M; x++) { for (int y = 0; y < N; y++) { arcImage[x][y] = 'O'; // O } } } public static void output() { for (int x = 0; x < M; x++) { for (int y = 0; y < N; y++) { System.out.print(arcImage[x][y]); } System.out.println(); } } /** * Recursively replace all pixels in the region R that are cOld with the color * c. * @param x * @param y * @param cOld The color that we want to match against. If the pixel is not colored cOld * it is not part of the region. * @param c */ public static void fill(int x, int y, char cOld, char c) { if (x < 0 || x >= M || y < 0 || y >= N) { return; } if (cOld == c) { return; } if (arcImage[x][y] != cOld) { return; // not part of the region } arcImage[x][y] = c; for (int nDir = 0; nDir < 4; nDir++) { fill(x + DX[nDir], y + DY[nDir], cOld, c); } } public static boolean boundsCheck(int x, int y) { if (x < 0 || x >= M || y < 0 || y >= N) { return false; } return true; } }![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks