Skip to content

Instantly share code, notes, and snippets.

@hiroshi-cl
Created June 25, 2013 06:50
Show Gist options
  • Save hiroshi-cl/5856491 to your computer and use it in GitHub Desktop.
Save hiroshi-cl/5856491 to your computer and use it in GitHub Desktop.
ACM-ICPC 模擬地区予選 2012 G: Ancient Commemorative Monolith 入力ビジュアライザ [Licence: NYSL Version 0.9982]
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.image.*;
import javax.imageio.ImageIO;
public class Visualizer {
private static final int SCALE = 8;
private static final Scanner sc = new Scanner(System.in);
public static void main(String... args) throws IOException {
for(int k = 0; sc.hasNext(); k++) {
final int N = sc.nextInt();
final int M = sc.nextInt();
if (N == 0 && M == 0)
break;
final File dir = new File(String.format("%02d", k));
dir.mkdir();
for(int i = 0; i < N; i++)
writeImage(dir, sc.next().charAt(0));
for(int i = 0; i < M; i++)
writeImage(dir, (char) ('0' + i));
}
}
public static void writeImage(final File dir, final char name) throws IOException {
final int H = sc.nextInt();
final int W = sc.nextInt();
final boolean[][] map = new boolean[H][W];
for (int i = 0; i < H; i++) {
final char[] line = sc.next().toCharArray();
for (int j = 0; j < W; j++)
map[i][j] = line[j] == '*';
}
final BufferedImage bi = new BufferedImage(W * SCALE, H * SCALE, BufferedImage.TYPE_BYTE_GRAY);
for (int i = 0; i < H * SCALE; i++)
for (int j = 0; j < W * SCALE; j++)
bi.setRGB(j, i, map[i / SCALE][j / SCALE] ? Color.BLACK.getRGB() : Color.WHITE.getRGB());
ImageIO.write(bi, "PNG", new File(dir, name + ".png"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment