import java.util.*;
public class Main
{
public static void main(String[] args)
{
// Read name file PGM
System.out.println("Enter name of file PGM");
String name = new Scanner(System.in).nextLine();
// Read all data
java.io.FileInputStream filePGM = File.OpenRead(name);
byte[] data = new byte[filePGM.getLength()];
filePGM.read(data, 0, filePGM.getLength());
filePGM.close();
// Read mesures file PGM
String mesures = "";
int i = 3;
do
{
mesures += (char)data[i];
i++;
} while (data[i] != 10);
i++;
String[] size;
int width, height;
size = mesures.split("[ ]", -1);
width = Integer.parseInt(size[0]);
height = Integer.parseInt(size[1]);
// Read color tone PGM
String colorTone = "";
do
{
colorTone += (char)data[i];
i++;
} while (data[i] != 10);
i++;
// Read pixels of PGM
int amount = 0;
for (int j = i; j < filePGM.getLength(); j++)
{
if (data[j] >= 200)
{
System.out.print(" ");
}
else if (data[j] >= 150 || data[j] <= 199)
{
System.out.print(".");
}
else if (data[j] >= 100 || data[j] <= 149)
{
System.out.print("-");
}
else if (data[j] >= 50 || data[j] <= 99)
{
System.out.print("=");
}
else if (data[j] >= 0 || data[j] <= 49)
{
System.out.print("#");
}
amount++;
if (amount % width == 0)
{
System.out.println();
}
}
}
}