Graphical Editor

From Progteam

Revision as of 00:12, 19 June 2008 by Mlc413 (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Graphical Editor
Problem Number 10267
Sorter: mlc413
Source: Programming Challenges
Link: http://acm.pku.edu.cn/JudgeOnline/problem?id=10267

This one works on all the sample input I can find but gets a mystery runtime error on the site. Seems to be unhappy with some formatting stuff. Any idea how to submit java files on the UVA site? (http://icpcres.ecs.baylor.edu/onlinejudge)


import java.util.*;

public class Main{

    public static Scanner in;
    public static char [][] grid;
    public static String name;
    public static boolean done = false;
    public static int M, N;
 
    public static void main(String[] args){
        in=new Scanner(System.in);

        doStuff();
        System.exit(0);
    }

    public static void doStuff(){
   
        while(!done){
            if(in.hasNext()){
                char c = in.next().charAt(0);
                getCommand(c);
            }
            else done = true;
        }
    }

    public static void getCommand(char c){
        switch(c){
        case 'I' :
            M = in.nextInt();
            N = in.nextInt();
            grid = new char[M+2][N+2];
            for(int i = 0; i <= M; i ++){
                for(int j = 0; j <= N; j++){
                    grid[i][j] = 'O';}}
            break;
        case 'C':
            for(int i = 1; i <= M; i ++){
                for(int j = 1; j <= N; j++){
                    grid[j][i] = 'O';}}
            break;
        case 'L': 
            int X = in.nextInt();
            int Y = in.nextInt();
            grid[X][Y] = in.next().charAt(0);
            break;
        case 'V':
            X = in.nextInt();
            int Y1 = in.nextInt();
            int Y2 = in.nextInt();
            char C = in.next().charAt(0);
            int min = Math.min(Y1, Y2);
            int max = Math.max(Y1, Y2);
            for(int i = min; i <= max; i++){
                grid[X][i] = C;
            }
            break;
        case 'H':
            
            int X1 = in.nextInt();
            int X2 = in.nextInt();
            Y = in.nextInt();
            C = in.next().charAt(0);
             min = Math.min(X1, X2);
             max = Math.max(X1, X2);
            for(int i = min; i <= max; i++){
                grid[i][Y] = C;
            }
            break;
        case 'K':
             X1 = in.nextInt();
             Y1 = in.nextInt();
             X2 = in.nextInt();
             Y2 = in.nextInt();
             C = in.next().charAt(0);
            for(int i = X1; i <= X2; i++){
                for(int j = Y1; j<=Y2; j++){
                    grid[i][j] = C;}
            }
            break;
        case 'F':
            X = in.nextInt();
            Y = in.nextInt();
            C = in.next().charAt(0);
            
            char cur = grid[X][Y];
            spread(X,Y,C, cur);
            break;
        case 'S':
            name = in.next();
            System.out.println(name);
            for(int i = 1; i <= N; i++){
                for(int j = 1; j<=M; j++){
                    System.out.print(grid[i][j]);
                }
                System.out.println();
            }
            break;
        case 'X': 
            done = true;
            break;
        default: 
            String junk = in.nextLine();
            break;
        }

    }
    public static void spread(int x, int y, char c, char cur){
        if(x>0 && y> 0 && x<=M && y<= N){
            if(grid[x][y] == cur ){
                grid[x][y] = c;
                spread(x-1, y-1, c, cur);
                spread(x-1, y, c, cur);
                spread(x-1, y+1, c, cur);
                spread(x, y-1, c, cur);
                spread(x, y+1, c, cur);
                spread(x+1, y-1, c, cur);
                spread(x+1, y, c, cur);
                spread(x+1, y+1, c, cur);
            }
        }
             
    }
}

Personal tools