The Goal
Rules
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 in a style you are given as input.
Game Input
Line 1: the width L of a letter represented in ASCII art. All letters are the same width.
Line 2: the height H of a letter represented in ASCII art. All letters are the same height.
Line 3: The line of text T, composed of N ASCII characters.
Following lines: the string of characters ABCDEFGHIJKLMNOPQRSTUVWXYZ? Represented in ASCII art.
The characters a to z are shown in ASCII art by their equivalent in upper case.
The characters that are not in the intervals [a-z] or [A-Z] will be shown as a question mark in ASCII art.
0 < H < 30
0 < N < 200
4
5
E
# ## ## ## ### ### ## # # ### ## # # # # # ### # ## # ## ## ### # # # # # # # # # # ### ###
# # # # # # # # # # # # # # # # # ### # # # # # # # # # # # # # # # # # # # # # # # #
### ## # # # ## ## # # ### # # ## # ### # # # # ## # # ## # # # # # # ### # # # ##
# # # # # # # # # # # # # # # # # # # # # # # # # # ## # # # # # # # # ### # # # #
# # ## ## ## ### # ## # # ### # # # ### # # # # # # # # # ## # ### # # # # # # ### #
### # ## # ###
4
5
MANHATTAN
# ## ## ## ### ### ## # # ### ## # # # # # ### # ## # ## ## ### # # # # # # # # # # ### ###
# # # # # # # # # # # # # # # # # ### # # # # # # # # # # # # # # # # # # # # # # # #
### ## # # # ## ## # # ### # # ## # ### # # # # ## # # ## # # # # # # ### # # # ##
# # # # # # # # # # # # # # # # # # # # # # # # # # ## # # # # # # # # ### # # # #
# # ## ## ## ### # ## # # ### # # # ### # # # # # # # # # ## # ### # # # # # # ### #
# # # ### # # # ### ### # ### ### # # # # # # # # # # # # # # ### ### # # ### ### # # ### # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Solution
We could write the alphabet in an array and look it up there. A much better way is reading in the first line of the alphabet and generate the output directly for the string we want to print:
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
class Solution {
static void Main(string[] args) {
int L = int.Parse(Console.ReadLine());
int H = int.Parse(Console.ReadLine());
string T = Console.ReadLine();
const int A = (int) 'A';
const int Z = (int) 'Z';
string str = T.ToUpper();
for (int i = 0; i < H; i++) {
string row = Console.ReadLine();
string ret = "";
foreach (var s in str) {
var c = (int) s;
if (c < A || c > Z)
ret+= row.Substring(L * (Z - A + 1), L);
else
ret+= row.Substring(L * (c - A), L);
}
Console.WriteLine(ret);
}
}
}
All images are copyright to Codingame