Home > Beyond, CodinGame, Java, snippets > ASCII Art – Challenge

ASCII Art – Challenge

November 17, 2015 Leave a comment Go to comments

This is the solution of the ASCII Art problem in the CodinGame page.
https://www.codingame.com/games/puzzles

import java.util.*;
import java.io.*;
import java.math.*;

/** @author Juan Mendoza grekz.wordpress.com
* ASCII art allows you to represent forms by using characters. To be precise, in our case, these forms are words. For example, the word “MANHATTAN” could be displayed as follows in ASCII art:
*
* # # # ### # # # ### ### # ###
* ### # # # # # # # # # # # # # #
* ### ### # # ### ### # # ### # #
* # # # # # # # # # # # # # # # #
* # # # # # # # # # # # # # # # #
*
* Your mission is to write a program that can display a line of text in ASCII art.
**/
class Solution {

  public static void main(String args[]) {
    Scanner in = new Scanner(System.in);
    int L = in.nextInt();
    in.nextLine();
    int H = in.nextInt();
    in.nextLine();
    String T = in.nextLine().toUpperCase();
    String [][] chars= new String[27][H];
    for (int i = 0; i < H; i++) {
        String ROW = in.nextLine();
        for(int j = 0; j < 27; j++){
            chars[j][i] = ROW.substring(j*L, (j+1) * L);
        }
    }
    for (int i = 0; i < H; i++) {
        for(char x : T.toCharArray() ){
            x -= 65;
            if(x < 0 || x > 26) x = 26;
            System.out.print(chars[x][i]);
        }
        System.out.println();
    }
  }
}
Categories: Beyond, CodinGame, Java, snippets
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: