SCALE = ".:-=+*#%@" # 낮은 칸부터 높은 칸까지 아홉 글자d, h = map(int, input().split())days = [list(map(int, input().split())) for _ in range(d)]lo = min(min(day) for day in days)hi = max(max(day) for day in days)width = hi - lo + 1for day in days: for x in day: # // 로 나눠야 정수다. / 는 실수라서 SCALE[2.5]처럼 칸 번호로 쓸 수 없다 print(SCALE[(x - lo) * 9 // width], end="") print()# 0.1도 단위 정수를 실수로 바꿔 10으로 나눈다: -5 → -0.5print(f"{lo / 10:.1f} {hi / 10:.1f}")
JavaScriptmain.js · 16 行
const SCALE = ".:-=+*#%@"; // 낮은 칸부터 높은 칸까지 아홉 글자const nums = require("fs").readFileSync(0, "utf8").trim().split(/\s+/).map(Number);const [d, h] = nums;const temps = nums.slice(2);const lo = Math.min(...temps);const hi = Math.max(...temps);const width = hi - lo + 1;for (let i = 0; i < d; i++) { for (let j = 0; j < h; j++) { const x = temps[i * h + j]; // / 는 실수라서 Math.floor로 정수 칸 번호를 만든다(SCALE[2.5]는 undefined) process.stdout.write(SCALE[Math.floor(((x - lo) * 9) / width)]); // 줄을 바꾸지 않고 쓴다 } process.stdout.write("\n");}console.log(`${(lo / 10).toFixed(1)} ${(hi / 10).toFixed(1)}`);
TypeScriptmain.ts · 17 行
import { readFileSync } from "node:fs";const SCALE = ".:-=+*#%@"; // 낮은 칸부터 높은 칸까지 아홉 글자const nums: number[] = readFileSync(0, "utf8").trim().split(/\s+/).map(Number);const [d, h] = nums;const temps: number[] = nums.slice(2);const lo: number = Math.min(...temps);const hi: number = Math.max(...temps);const width: number = hi - lo + 1;for (let i = 0; i < d; i++) { for (let j = 0; j < h; j++) { const x: number = temps[i * h + j]; // / 는 실수라서 Math.floor로 정수 칸 번호를 만든다 process.stdout.write(SCALE[Math.floor(((x - lo) * 9) / width)]); // 줄을 바꾸지 않고 쓴다 } process.stdout.write("\n");}console.log(`${(lo / 10).toFixed(1)} ${(hi / 10).toFixed(1)}`);
JavaMain.java · 36 行
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.io.PrintWriter;import java.util.Locale;import java.util.StringTokenizer;public class Main { static final String SCALE = ".:-=+*#%@"; // 낮은 칸부터 높은 칸까지 아홉 글자 public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(in.readLine()); int d = Integer.parseInt(st.nextToken()), h = Integer.parseInt(st.nextToken()); int[][] t = new int[d][h]; int lo = Integer.MAX_VALUE, hi = Integer.MIN_VALUE; for (int i = 0; i < d; i++) { st = new StringTokenizer(in.readLine()); for (int j = 0; j < h; j++) { t[i][j] = Integer.parseInt(st.nextToken()); lo = Math.min(lo, t[i][j]); hi = Math.max(hi, t[i][j]); } } int width = hi - lo + 1; PrintWriter out = new PrintWriter(System.out); // print를 여러 번 해도 한 번에 내보낸다 for (int[] day : t) { // int끼리는 몫만 남는다: 곱하기를 먼저 해야 한다((x - lo) / width * 9는 늘 0) for (int x : day) out.print(SCALE.charAt((x - lo) * 9 / width)); out.println(); } // int를 double로 바꿔 나눈다: -5 / 10은 0이지만 -5 / 10.0은 -0.5 out.println(String.format(Locale.ROOT, "%.1f %.1f", lo / 10.0, hi / 10.0)); out.flush(); }}
C#Main.cs · 31 行
using System;using System.Globalization;using System.IO;using System.Linq;class Program{ const string Scale = ".:-=+*#%@"; // 낮은 칸부터 높은 칸까지 아홉 글자 static void Main() { int[] dh = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray(); int d = dh[0]; var days = new int[d][]; for (int i = 0; i < d; i++) days[i] = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray(); int lo = days.Min(r => r.Min()), hi = days.Max(r => r.Max()); int width = hi - lo + 1; var out_ = new StreamWriter(Console.OpenStandardOutput()); // Write를 여러 번 해도 한 번에 내보낸다 foreach (int[] day in days) { // int끼리는 몫만 남는다: 곱하기를 먼저 foreach (int x in day) out_.Write(Scale[(x - lo) * 9 / width]); out_.Write('\n'); } // int를 double로 바꿔 나눈다: -5 / 10은 0, -5 / 10.0은 -0.5 var inv = CultureInfo.InvariantCulture; out_.Write((lo / 10.0).ToString("F1", inv) + " " + (hi / 10.0).ToString("F1", inv) + "\n"); out_.Flush(); }}
C++main.cpp · 28 行
#include <algorithm>#include <iomanip>#include <iostream>#include <string>#include <vector>int main() { const std::string SCALE = ".:-=+*#%@"; // 낮은 칸부터 높은 칸까지 아홉 글자 std::ios::sync_with_stdio(false); int d, h; std::cin >> d >> h; std::vector<std::vector<int>> t(d, std::vector<int>(h)); int lo = 1000, hi = -1000; for (auto& day : t) for (int& x : day) { std::cin >> x; lo = std::min(lo, x); hi = std::max(hi, x); } int width = hi - lo + 1; for (const auto& day : t) { // int끼리는 몫만 남는다: 곱하기를 먼저. << 는 줄을 바꾸지 않는다 for (int x : day) std::cout << SCALE[(x - lo) * 9 / width]; std::cout << '\n'; } // int를 double로 바꿔 나눈다: -5 / 10은 0이지만 -5 / 10.0은 -0.5 std::cout << std::fixed << std::setprecision(1) << lo / 10.0 << ' ' << hi / 10.0 << '\n';}
Cmain.c · 25 行
#include <stdio.h>static const char SCALE[] = ".:-=+*#%@"; /* 낮은 칸부터 높은 칸까지 아홉 글자 */static int t[100][48];int main(void) { int d, h; scanf("%d %d", &d, &h); int lo = 1000, hi = -1000; for (int i = 0; i < d; i++) for (int j = 0; j < h; j++) { scanf("%d", &t[i][j]); if (t[i][j] < lo) lo = t[i][j]; if (t[i][j] > hi) hi = t[i][j]; } int width = hi - lo + 1; for (int i = 0; i < d; i++) { /* int끼리는 몫만 남는다: 곱하기를 먼저. putchar는 줄을 바꾸지 않는다 */ for (int j = 0; j < h; j++) putchar(SCALE[(t[i][j] - lo) * 9 / width]); putchar('\n'); } /* int를 double로 바꿔 나눈다: -5 / 10은 0이지만 -5 / 10.0은 -0.5 */ printf("%.1f %.1f\n", lo / 10.0, hi / 10.0); return 0;}