Official

B - ASCII Art Editorial by en_translator


The title of this problem, ASCII art, refers to an illustration represented by texts using the characters in the ASCII code. Huge illustrations consisting of tens of liens as in Sample Input 4 was often use in the early days of the internet. Reference: Wikipedia

This problem can be solved by appropriately converting sequences into strings. In C++, an easy way is to use the ASCII code. (Reference: Wikipedia) Using the ASCII code, the \(n\)-th capital alphabet can be found by the following expression:

char c = `A` + n - 1;

Using this method to appropriately convert the sequences into string in a for loop, this problem can be solved.

  • Sample code (C++)
#include <iostream>
#include <string>
using namespace std;

int main() {
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    string S(W, '.');
    for (int j = 0; j < W; j++) {
      int x;
      cin >> x;
      if (x != 0) S[j] = 'A' + x - 1;
    }
    cout << S << "\n";
  }
}

posted:
last update: