题目背景
本题灵感来源于 P1000 超级玛丽游戏。
本题是 语言博物馆 项目的一部分。
题目描述
你需要输出一个被称为 “字符艺术”(ASCII ART) 的图像。
输出的内容根据代码的编程语言决定。
例如,如果您使用 Swift 编写代码,输出可能是这样的:
███████╗ ██╗ ██╗ ██╗ ███████╗ ████████╗
██╔════╝ ██║ ██║ ██║ ██╔════╝ ╚══██╔══╝
███████╗ ██║ █╗ ██║ ██║ █████╗ ██║
╚════██║ ██║███╗██║ ██║ ██╔══╝ ██║
███████║ ╚███╔███╔╝ ██║ ██║ ██║
╚══════╝ ╚══╝╚══╝ ╚═╝ ╚═╝ ╚═╝
而 JAVA 是这样的:
██╗ █████╗ ██╗ ██╗ █████╗
██║ ██╔══██╗ ██║ ██║ ██╔══██╗
██║ ███████║ ██║ ██║ ███████║
██ ██║ ██╔══██║ ╚██╗ ██╔╝ ██╔══██║
╚█████╔╝ ██║ ██║ ╚████╔╝ ██║ ██║
╚════╝ ╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝输入格式
本题没有输入。
输出格式
输出一个 ASCII 图像。
需要注意的是:本题没有标准输出。你也不需要提交。
但欢迎任何人贡献代码。
提示说明
以下是几组样例。
C++ 11
#include <iostream>
int main() {
std::cout << " ██████╗" << std::endl;
std::cout << " ██╔════╝ ██╗ ██╗" << std::endl;
std::cout << " ██║ ███████╗ ███████╗" << std::endl;
std::cout << " ██║ ╚══██╔═╝ ╚══██╔═╝" << std::endl;
std::cout << " ╚██████╗ ╚═╝ ╚═╝" << std::endl;
std::cout << " ╚═════╝" << std::endl;
return 0;
}JAVA 8
public class Main {
public static void main(String[] args) {
System.out.println(" ██╗ █████╗ ██╗ ██╗ █████╗");
System.out.println(" ██║ ██╔══██╗ ██║ ██║ ██╔══██╗");
System.out.println(" ██║ ███████║ ██║ ██║ ███████║");
System.out.println(" ██ ██║ ██╔══██║ ╚██╗ ██╔╝ ██╔══██║");
System.out.println(" ╚█████╔╝ ██║ ██║ ╚████╔╝ ██║ ██║");
System.out.println(" ╚════╝ ╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝");
}
}Swift 5
由于洛谷 IDE OL 没有提供 Swift 环境,这里给出一个在线测试环境以确保代码正确
https://www.bejson.com/runcode/swift/
import Foundation
let str = """
███████╗ ██╗ ██╗ ██╗ ███████╗ ████████╗
██╔════╝ ██║ ██║ ██║ ██╔════╝ ╚══██╔══╝
███████╗ ██║ █╗ ██║ ██║ █████╗ ██║
╚════██║ ██║███╗██║ ██║ ██╔══╝ ██║
███████║ ╚███╔███╔╝ ██║ ██║ ██║
╚══════╝ ╚══╝╚══╝ ╚═╝ ╚═╝ ╚═╝
"""
print(str)
Command Lisp SBCL 2.0
由于洛谷 IDE OL 没有提供 Lisp 环境,这里给出一个在线测试环境以确保代码正确
https://www.bejson.com/runcode/commonlisp/
(defun print-ascii-art ()
(format t " ██╗ ██╗ ███████╗ ██████╗~%")
(format t " ██║ ██║ ██╔════╝ ██╔══██╗~%")
(format t " ██║ ██║ ███████╗ ██████╔╝~%")
(format t " ██║ ██║ ╚════██║ ██╔═══╝~%")
(format t " ███████╗ ██║ ███████║ ██║~%")
(format t " ╚══════╝ ╚═╝ ╚══════╝ ╚═╝~%"))
(print-ascii-art)
你可以使用如下代码生成 “字符艺术”
代码来自 Claude 3.5 Sonnet
#include <iostream>
#include <string>
#include <vector>
#include <map>
// 定义字母、数字和符号的ASCII艺术表示
std::map<char, std::vector<std::string>> letterArt = {
{'A', {
" █████╗ ",
" ██╔══██╗",
" ███████║",
" ██╔══██║",
" ██║ ██║",
" ╚═╝ ╚═╝"
}},
{'B', {
" ██████╗ ",
" ██╔══██╗",
" ██████╔╝",
" ██╔══██╗",
" ██████╔╝",
" ╚═════╝ "
}},
{'C', {
" ██████╗",
" ██╔════╝",
" ██║ ",
" ██║ ",
" ╚██████╗",
" ╚═════╝"
}},
{'D', {
" ██████╗ ",
" ██╔══██╗",
" ██║ ██║",
" ██║ ██║",
" ██████╔╝",
" ╚═════╝ "
}},
{'E', {
" ███████╗",
" ██╔════╝",
" █████╗ ",
" ██╔══╝ ",
" ███████╗",
" ╚══════╝"
}},
{'F', {
" ███████╗",
" ██╔════╝",
" █████╗ ",
" ██╔══╝ ",
" ██║ ",
" ╚═╝ "
}},
{'G', {
" ██████╗ ",
" ██╔════╝ ",
" ██║ ███╗",
" ██║ ██║",
" ╚██████╔╝",
" ╚═════╝ "
}},
{'H', {
" ██╗ ██╗",
" ██║ ██║",
" ███████║",
" ██╔══██║",
" ██║ ██║",
" ╚═╝ ╚═╝"
}},
{'I', {
" ██╗",
" ██║",
" ██║",
" ██║",
" ██║",
" ╚═╝"
}},
{'J', {
" ██╗",
" ██║",
" ██║",
" ██ ██║",
" ╚█████╔╝",
" ╚════╝ "
}},
{'K', {
" ██╗ ██╗",
" ██║ ██╔╝",
" █████╔╝ ",
" ██╔═██╗ ",
" ██║ ██╗",
" ╚═╝ ╚═╝"
}},
{'L', {
" ██╗ ",
" ██║ ",
" ██║ ",
" ██║ ",
" ███████╗",
" ╚══════╝"
}},
{'M', {
" ███╗ ███╗",
" ████╗ ████║",
" ██╔████╔██║",
" ██║╚██╔╝██║",
" ██║ ╚═╝ ██║",
" ╚═╝ ╚═╝"
}},
{'N', {
" ███╗ ██╗",
" ████╗ ██║",
" ██╔██╗ ██║",
" ██║╚██╗██║",
" ██║ ╚████║",
" ╚═╝ ╚═══╝"
}},
{'O', {
" ██████╗ ",
" ██╔═══██╗",
" ██║ ██║",
" ██║ ██║",
" ╚██████╔╝",
" ╚═════╝ "
}},
{'P', {
" ██████╗ ",
" ██╔══██╗",
" ██████╔╝",
" ██╔═══╝ ",
" ██║ ",
" ╚═╝ "
}},
{'Q', {
" ██████╗ ",
" ██╔═══██╗",
" ██║ ██║",
" ██║▄▄ ██║",
" ╚██████╔╝",
" ╚══??═╝ "
}},
{'R', {
" ██████╗ ",
" ██╔══██╗",
" ██████╔╝",
" ██╔══██╗",
" ██║ ██║",
" ╚═╝ ╚═╝"
}},
{'S', {
" ███████╗",
" ██╔════╝",
" ███████╗",
" ╚════██║",
" ███████║",
" ╚══════╝"
}},
{'T', {
" ████████╗",
" ╚══██╔══╝",
" ██║ ",
" ██║ ",
" ██║ ",
" ╚═╝ "
}},
{'U', {
" ██╗ ██╗",
" ██║ ██║",
" ██║ ██║",
" ██║ ██║",
" ╚██████╔╝",
" ╚═════╝ "
}},
{'V', {
" ██╗ ██╗",
" ██║ ██║",
" ██║ ██║",
" ╚██╗ ██╔╝",
" ╚████╔╝ ",
" ╚═══╝ "
}},
{'W', {
" ██╗ ██╗",
" ██║ ██║",
" ██║ █╗ ██║",
" ██║███╗██║",
" ╚███╔███╔╝",
" ╚══╝╚══╝ "
}},
{'X', {
" ██╗ ██╗",
" ╚██╗██╔╝",
" ╚███╔╝ ",
" ██╔██╗ ",
" ██╔╝ ██╗",
" ╚═╝ ╚═╝"
}},
{'Y', {
" ██╗ ██╗",
" ╚██╗ ██╔╝",
" ╚████╔╝ ",
" ╚██╔╝ ",
" ██║ ",
" ╚═╝ "
}},
{'Z', {
" ███████╗",
" ╚══███╔╝",
" ███╔╝ ",
" ███╔╝ ",
" ███████╗",
" ╚══════╝"
}},
{'0', {
" ██████╗ ",
" ██╔═████╗",
" ██║██╔██║",
" ████╔╝██║",
" ╚██████╔╝",
" ╚═════╝ "
}},
{'1', {
" ██╗",
" ███║",
" ╚██║",
" ██║",
" ██║",
" ╚═╝"
}},
{'2', {
" ██████╗ ",
" ╚════██╗",
" █████╔╝",
" ██╔═══╝ ",
" ███████╗",
" ╚══════╝"
}},
{'3', {
" ██████╗ ",
" ╚════██╗",
" █████╔╝",
" ╚═══██╗",
" ██████╔╝",
" ╚═════╝ "
}},
{'4', {
" ██╗ ██╗",
" ██║ ██║",
" ███████║",
" ╚════██║",
" ██║",
" ╚═╝"
}},
{'5', {
" ███████╗",
" ██╔════╝",
" ███████╗",
" ╚════██║",
" ███████║",
" ╚══════╝"
}},
{'6', {
" ██████╗ ",
" ██╔════╝ ",
" ███████╗ ",
" ██╔═══██╗",
" ╚██████╔╝",
" ╚═════╝ "
}},
{'7', {
" ███████╗",
" ╚════██║",
" ██╔╝",
" ██╔╝ ",
" ██║ ",
" ╚═╝ "
}},
{'8', {
" █████╗ ",
" ██╔══██╗",
" ╚█████╔╝",
" ██╔══██╗",
" ╚█████╔╝",
" ╚════╝ "
}},
{'9', {
" █████╗ ",
" ██╔══██╗",
" ╚██████║",
" ╚═══██║",
" █████╔╝",
" ╚════╝ "
}},
{'+', {
" ",
" ██╗ ",
" ███████╗ ",
" ╚══██╔═╝ ",
" ╚═╝ ",
" "
}},
{'-', {
" ",
" ",
" ███████╗ ",
" ╚══════╝ ",
" ",
" "
}},
{'*', {
" ██╗ ██╗ ",
" ╚████╔╝ ",
" ████████╗",
" ╚██╔═██╔╝",
" ╚═╝ ╚═╝ ",
" "
}},
{'/', {
" ██╗",
" ██╔╝",
" ██╔╝ ",
" ██╔╝ ",
" ██╔╝ ",
" ╚═╝ "
}},
{'=', {
" ",
" ███████╗ ",
" ╚══════╝ ",
" ███████╗ ",
" ╚══════╝ ",
" "
}},
{'!', {
" ██╗",
" ██║",
" ██║",
" ╚═╝",
" ██╗",
" ╚═╝"
}},
{'#', {
" ██╗ ██╗",
" ██║ ██║",
" ███████║",
" ╚════██║",
" ██╗ ██║",
" ╚═╝ ╚═╝"
}},
{' ', {
" ",
" ",
" ",
" ",
" ",
" "
}}
};
// 将输入的字符串转换为ASCII艺术
void printAsciiArt(const std::string& input) {
std::vector<std::string> output(6, ""); // 6行输出
for (char c : input) {
c = toupper(c); // 转换为大写
if (letterArt.find(c) != letterArt.end()) {
for (int i = 0; i < 6; ++i) {
output[i] += letterArt[c][i];
}
} else {
// 对于不支持的字符,添加空格
for (int i = 0; i < 6; ++i) {
output[i] += " "; // 5个空格,与空格字符宽度一致
}
}
}
// 打印结果
for (const auto& line : output) {
std::cout << line << std::endl;
}
}
int main() {
std::string input;
while (true) {
std::cout << "Enter a string (or 'quit' to exit): ";
std::getline(std::cin, input);
if (input == "quit") {
break;
}
printAsciiArt(input);
std::cout << std::endl;
}
return 0;
}