codingame ASCII Art
久しぶりに、codingameをやってみました。
超意訳で問題説明してみます。
アスキーアートを作ろう
入力
Line 1: the width L of a letter represented in ASCII art. All letters are the same width.
1行目はアスキーアートの幅です。全部の文字は同じ幅です。Lとします。
Line 2: the height H of a letter represented in ASCII art. All letters are the same height.
2行目はアスキーアートの高さです。全部の文字は同じ高さです。Hとします。
Line 3: The line of text T, composed of N ASCII characters.
3行目はアスキーアートに変換する文字です。Tとします。
Following lines: the string of characters ABCDEFGHIJKLMNOPQRSTUVWXYZ? Represented in ASCII art.
その後ろには、ABCDEFGHIJKLMNOPQRSTUVWXYZ?のアスキーアートの元ネタです。
出力
The text T in ASCII art.
入力のTをアスキーアートにしてください。
The characters a to z are shown in ASCII art by their equivalent in upper case.
小文字a-zは大文字に変換してください。
The characters that are not in the intervals [a-z] or [A-Z] will be shown as a question mark in ASCII art.
アルファベット以外の場合は?のアスキーアートにしてください。
そんなわけでpythonで書いてみました。
import sys import math # Auto-generated code below aims at helping you parse # the standard input according to the problem statement. l = int(raw_input()) h = int(raw_input()) t = raw_input() rows = [raw_input() for i in xrange(h)] # Write an action using print # To debug: print >> sys.stderr, "Debug messages..." def convert(x): c = ord(x.upper()) - 65 if c < 0 or 25 < c: c = 26 return c indexes = [convert(x) for x in t] for row in rows: print ''.join([row[l * i:l * i + l] for i in indexes])
アスキーアートの元ネタを変換して持たせようかとも思いましたが、pythonの場合はそのまま保持していてもスライス表記で簡単に扱えるため、変換せず。
一方、アルファベット以外は逆に事前に変換しています。