All pastes #1767421 Raw Edit

skyline

public text v1 · immutable
#1767421 ·published 2010-01-27 01:37 UTC
rendered paste body
import java.util.*;
import java.io.*;

public class skyline
{
	public static void main(String args[]) throws FileNotFoundException
	{
		Scanner input = new Scanner(new File("skyline.in"));
		
		int runTimes = input.nextLine().charAt(0) - 48;
		do{
			int m = input.nextLine().charAt(0) - 48;
			
			int[][] block= new int[m][1];
			int highest = 0;
			for(int i = 0; i < m; i++)
				block[i][0] = 0;
			
			for(int i = 0; i<m;i++){
				String street = input.nextLine();
				int streetHigh = 0;
				for(int j = 0; j<m; j++)
				{
					int x = street.charAt(j) - 48;
					
					
					if(x > streetHigh){
						if(x > highest)
						{
							block = resize(block,x, m, highest);
							highest = x;
						}
						
						for(int k = streetHigh; k<x;k++)
							block[i][k] = j + 1;
							
						streetHigh = x;
					}
				}
			}
			
			
			for(int i = highest-1;i>=0;i--)
			{
				for(int j = 0;j<m;j++)
				{
					if(block[j][i] == 0)
						System.out.print(".");
					else
						System.out.print(block[j][i]);
				}	
				System.out.println("");		
			}
		}while((runTimes -= 1) != 0);	
		
	}
	
	public static int[][] resize(int[][] original, int size, int m, int len)
	{
		int[][] resized = new int[m][size];
		for(int i = 0; i < m; i++)
		{
			
			for(int j = 0; j < len; j++)
				resized[i][j] = original[i][j];
			for(int j = len; j < size;j++)
				resized[i][j] = 0;
		}
		return resized;
					
	}
	
	
}