import sys# 파이썬에는 상수 문법이 없다: 대문자 이름은 "바꾸지 말자"는 약속일 뿐이다KB = 1024MB = 1024 * KBGB = 1024 * MBALLOWANCE = 3 * GB + 500 * MB # 기본으로 주는 양BLOCK = 100 * MB # 넘은 양을 세는 묶음PRICE = 550 # 묶음 하나의 요금(원)UNIT = {"B": 1, "KB": KB, "MB": MB, "GB": GB}lines = sys.stdin.read().split("\n")n = int(lines[0])total = 0for i in range(1, n + 1): a, u = lines[i].split() total += int(a) * UNIT[u]blocks = 0if total > ALLOWANCE: blocks = (total - ALLOWANCE + BLOCK - 1) // BLOCK # 올림print(total)print(blocks)print(blocks * PRICE)
JavaScriptmain.js · 24 行
// const는 다시 넣으면 실행 중에 TypeError가 난다const KB = 1024;const MB = 1024 * KB;const GB = 1024 * MB;const ALLOWANCE = 3 * GB + 500 * MB; // 기본으로 주는 양const BLOCK = 100 * MB; // 넘은 양을 세는 묶음const PRICE = 550; // 묶음 하나의 요금(원)const UNIT = { B: 1, KB: KB, MB: MB, GB: GB };const lines = require("fs").readFileSync(0, "utf8").split("\n");const n = Number(lines[0]);let total = 0;for (let i = 1; i <= n; i++) { const [a, u] = lines[i].trim().split(" "); total += Number(a) * UNIT[u];}let blocks = 0;if (total > ALLOWANCE) { blocks = Math.floor((total - ALLOWANCE + BLOCK - 1) / BLOCK); // 올림}console.log(String(total));console.log(String(blocks));console.log(String(blocks * PRICE));
TypeScriptmain.ts · 26 行
import { readFileSync } from "node:fs";// const는 다시 넣으면 컴파일 오류다const KB: number = 1024;const MB: number = 1024 * KB;const GB: number = 1024 * MB;const ALLOWANCE: number = 3 * GB + 500 * MB; // 기본으로 주는 양const BLOCK: number = 100 * MB; // 넘은 양을 세는 묶음const PRICE: number = 550; // 묶음 하나의 요금(원)const UNIT: Record<string, number> = { B: 1, KB: KB, MB: MB, GB: GB };const lines: string[] = readFileSync(0, "utf8").split("\n");const n: number = Number(lines[0]);let total: number = 0;for (let i = 1; i <= n; i++) { const [a, u] = lines[i].trim().split(" "); total += Number(a) * UNIT[u];}let blocks: number = 0;if (total > ALLOWANCE) { blocks = Math.floor((total - ALLOWANCE + BLOCK - 1) / BLOCK); // 올림}console.log(String(total));console.log(String(blocks));console.log(String(blocks * PRICE));
JavaMain.java · 40 行
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;public class Main { // static final 상수. 1024L처럼 L을 붙여야 곱셈이 long으로 계산된다 static final long KB = 1024L; static final long MB = 1024 * KB; static final long GB = 1024 * MB; static final long ALLOWANCE = 3 * GB + 500 * MB; // 기본으로 주는 양 static final long BLOCK = 100 * MB; // 넘은 양을 세는 묶음 static final long PRICE = 550; // 묶음 하나의 요금(원) static long unit(String u) { switch (u) { case "KB": return KB; case "MB": return MB; case "GB": return GB; default: return 1; } } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine().trim()); long total = 0; for (int i = 0; i < n; i++) { String[] parts = br.readLine().trim().split(" "); total += Long.parseLong(parts[0]) * unit(parts[1]); } long blocks = 0; if (total > ALLOWANCE) { blocks = (total - ALLOWANCE + BLOCK - 1) / BLOCK; // 올림 } System.out.println(total); System.out.println(blocks); System.out.println(blocks * PRICE); }}
C#Main.cs · 43 行
using System;class Program{ // const 상수: 컴파일할 때 값이 정해진다 const long KB = 1024L; const long MB = 1024 * KB; const long GB = 1024 * MB; const long ALLOWANCE = 3 * GB + 500 * MB; // 기본으로 주는 양 const long BLOCK = 100 * MB; // 넘은 양을 세는 묶음 const long PRICE = 550; // 묶음 하나의 요금(원) static long Unit(string u) { switch (u) { case "KB": return KB; case "MB": return MB; case "GB": return GB; default: return 1; } } static void Main() { int n = int.Parse(Console.ReadLine().Trim()); long total = 0; for (int i = 0; i < n; i++) { string[] parts = Console.ReadLine().Trim().Split(' '); total += long.Parse(parts[0]) * Unit(parts[1]); } long blocks = 0; if (total > ALLOWANCE) { blocks = (total - ALLOWANCE + BLOCK - 1) / BLOCK; // 올림 } Console.WriteLine(total); Console.WriteLine(blocks); Console.WriteLine(blocks * PRICE); }}
C++main.cpp · 34 行
#include <iostream>#include <string>using namespace std;// constexpr 상수: 컴파일할 때 계산되고, 넘치면 컴파일 오류다constexpr long long KB = 1024;constexpr long long MB = 1024 * KB;constexpr long long GB = 1024 * MB;constexpr long long ALLOWANCE = 3 * GB + 500 * MB; // 기본으로 주는 양constexpr long long BLOCK = 100 * MB; // 넘은 양을 세는 묶음constexpr long long PRICE = 550; // 묶음 하나의 요금(원)int main() { int n; cin >> n; long long total = 0; for (int i = 0; i < n; i++) { long long a; string u; cin >> a >> u; long long unit = 1; if (u == "KB") unit = KB; else if (u == "MB") unit = MB; else if (u == "GB") unit = GB; total += a * unit; } long long blocks = 0; if (total > ALLOWANCE) { blocks = (total - ALLOWANCE + BLOCK - 1) / BLOCK; // 올림 } cout << total << '\n' << blocks << '\n' << blocks * PRICE << '\n'; return 0;}
Cmain.c · 33 行
#include <stdio.h>#include <string.h>/* #define은 글자를 그대로 바꿔 끼운다: 식은 꼭 괄호로 싼다 */#define KB 1024LL#define MB (1024 * KB)#define GB (1024 * MB)#define ALLOWANCE (3 * GB + 500 * MB) /* 기본으로 주는 양 */#define BLOCK (100 * MB) /* 넘은 양을 세는 묶음 */#define PRICE 550 /* 묶음 하나의 요금(원) */int main(void) { int n; if (scanf("%d", &n) != 1) return 1; long long total = 0; for (int i = 0; i < n; i++) { long long a; char u[4]; if (scanf("%lld %3s", &a, u) != 2) return 1; long long unit = 1; if (strcmp(u, "KB") == 0) unit = KB; else if (strcmp(u, "MB") == 0) unit = MB; else if (strcmp(u, "GB") == 0) unit = GB; total += a * unit; } long long blocks = 0; if (total > ALLOWANCE) { blocks = (total - ALLOWANCE + BLOCK - 1) / BLOCK; /* 올림 */ } printf("%lld\n%lld\n%lld\n", total, blocks, blocks * PRICE); return 0;}
Craykonmain.cray · 38 行
// 크레이콘에는 상수가 없다: 바꾸지 않기로 약속한 변수로 둔다킬로 = 1024;메가 = 1024 * 킬로;기가 = 1024 * 메가;기본량 = 3 * 기가 + 500 * 메가; // 기본으로 주는 양묶음 = 100 * 메가; // 넘은 양을 세는 묶음묶음요금 = 550; // 묶음 하나의 요금(원)기록수 = 控制台.读行().转数字();합 = 0;循环 (i = 0; i < 기록수; i++){ 칸들 = 控制台.读行().去空白().分割(); 양 = 칸들[0].转数字(); 단위 = 1; 如果 (칸들[1] == "KB") { 단위 = 킬로; } 否则 如果 (칸들[1] == "MB") { 단위 = 메가; } 否则 如果 (칸들[1] == "GB") { 단위 = 기가; } 합 += 양 * 단위;}묶음수 = 0;如果 (합 > 기본량){ 묶음수 = 数学.商(합 - 기본량 + 묶음 - 1, 묶음); // 올림}控制台.输出(합);控制台.输出(묶음수);控制台.输出(묶음수 * 묶음요금);