Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.20 KB | None | 0 0
  1. package com.bakes;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileReader;
  6. import java.io.FileWriter;
  7. import java.io.IOException;
  8. import java.io.PrintWriter;
  9. import java.util.Arrays;
  10.  
  11. public class A {
  12.     public static void main(String[] args) {
  13.         A park = new A();
  14.         park.calculate();
  15.  
  16.     }  
  17.  
  18.     private void calculate() {
  19.         BufferedReader in;
  20.         String strLine1;
  21.         String strLine2;
  22.         String strLine3;
  23.         PrintWriter out;
  24.         try {
  25.             in = new BufferedReader(new FileReader("input.in"));
  26.             in.readLine();
  27.             FileWriter outFile = new FileWriter("output.txt");
  28.             out = new PrintWriter(outFile);
  29.             int n = 0;
  30.  
  31.             while ((strLine1 = in.readLine()) != null) {
  32.                 n++;
  33.                
  34.                 String[] data = strLine1.split(" ");
  35.                 System.out.println(strLine1);
  36.                 int height = Integer.parseInt(data[0]);
  37.                 int width = Integer.parseInt(data[1]);
  38.                 char[][] image = new char[height][width];
  39.                 for (int i = 0; i<height; i++)
  40.                 {
  41.                     char[] line = in.readLine().toCharArray();
  42.                     for (int j = 0; j < width; j++)
  43.                     {
  44.                             image[i][j] = line[j];
  45.                     }
  46.                 }
  47.                
  48.                 for (int i = 0; i<height-1; i++)
  49.                 {
  50.                     for (int j = 0; j < width-1; j++)
  51.                     {
  52.                         if ((image[i][j] == '#') && (image[i][j+1] == '#') && (image[i+1][j] == '#') && (image[i+1][j+1] == '#'))
  53.                         {
  54.                             image[i][j] = '/';
  55.                             image[i][j+1] = '\\';
  56.                             image[i+1][j] = '\\';
  57.                             image[i+1][j+1] = '/';
  58.                         }
  59.                     }
  60.                 }
  61.                
  62.                 boolean done = true;
  63.                 for (int i = 0; i<height; i++)
  64.                 {
  65.                     for (int j = 0; j < width; j++)
  66.                     {
  67.                         if (image[i][j] == '#')
  68.                         {
  69.                             done = false;
  70.                         }
  71.                     }
  72.                 }
  73.                 out.println("Case #"+n+":");
  74.                 if (!done)
  75.                 {
  76.                     out.println("Impossible");
  77.                 }
  78.                 else if (true)
  79.                 {
  80.                     for (int i = 0; i<height; i++)
  81.                     {
  82.                         String s = "";
  83.                         for (int j = 0; j < width; j++)
  84.                         {
  85.                             s += image[i][j];
  86.                         }
  87.                         out.println(s);
  88.                    
  89.                     }
  90.                 }
  91.             }
  92.             out.close();
  93.         } catch (FileNotFoundException e) {
  94.             // TODO Auto-generated catch block
  95.             e.printStackTrace();
  96.         } catch (IOException e) {
  97.             // TODO Auto-generated catch block
  98.             e.printStackTrace();
  99.         }
  100.        
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement