n = int(input())best, best_slope = 1, -1.0for i in range(1, n + 1): h, d = map(int, input().split()) # 100을 먼저 곱하고 나눈다: h / d * 100은 7 / 100 * 100 = 7.000000000000001이 된다 slope = h * 100 / d if slope <= 3: print("平坦") elif slope <= 7: print("ゆるやか") elif slope <= 14: print("急") else: print("押して歩く") if slope > best_slope: # 같으면 앞 구간을 그대로 둔다 best, best_slope = i, slopeprint(best)
JavaScriptmain.js · 19 行
const [n, ...v] = require("fs").readFileSync(0, "utf8").trim().split(/\s+/).map(Number);const sign = (slope) => (slope <= 3 ? "平坦" : slope <= 7 ? "ゆるやか" : slope <= 14 ? "急" : "押して歩く");const out = [];let best = 1;let bestSlope = -1;for (let i = 1; i <= n; i++) { const h = v[2 * i - 2]; const d = v[2 * i - 1]; // 100을 먼저 곱하고 나눈다: h / d * 100은 7 / 100 * 100 = 7.000000000000001이 된다 const slope = (h * 100) / d; out.push(sign(slope)); if (slope > bestSlope) { // 같으면 앞 구간을 그대로 둔다 best = i; bestSlope = slope; }}out.push(String(best));console.log(out.join("\n"));
TypeScriptmain.ts · 21 行
import { readFileSync } from "node:fs";const [n, ...v]: number[] = readFileSync(0, "utf8").trim().split(/\s+/).map(Number);const sign = (slope: number): string => slope <= 3 ? "平坦" : slope <= 7 ? "ゆるやか" : slope <= 14 ? "急" : "押して歩く";const out: string[] = [];let best: number = 1;let bestSlope: number = -1;for (let i = 1; i <= n; i++) { const h: number = v[2 * i - 2]; const d: number = v[2 * i - 1]; // 100을 먼저 곱하고 나눈다: h / d * 100은 7 / 100 * 100 = 7.000000000000001이 된다 const slope: number = (h * 100) / d; out.push(sign(slope)); if (slope > bestSlope) { // 같으면 앞 구간을 그대로 둔다 best = i; bestSlope = slope; }}out.push(String(best));console.log(out.join("\n"));
JavaMain.java · 36 行
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.StringTokenizer;public class Main { static String sign(double slope) { if (slope <= 3) return "平坦"; if (slope <= 7) return "ゆるやか"; if (slope <= 14) return "急"; return "押して歩く"; } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine().trim()); StringBuilder out = new StringBuilder(); int best = 1; double bestSlope = -1; for (int i = 1; i <= n; i++) { StringTokenizer st = new StringTokenizer(br.readLine()); int h = Integer.parseInt(st.nextToken()); int d = Integer.parseInt(st.nextToken()); // int끼리 나누면 몫만 남으므로 double로 바꾼 뒤 나눈다. // 100을 먼저 곱한다: h / d * 100은 7 / 100 * 100 = 7.000000000000001이 된다 double slope = h * 100.0 / d; out.append(sign(slope)).append('\n'); if (slope > bestSlope) { // 같으면 앞 구간을 그대로 둔다 best = i; bestSlope = slope; } } out.append(best).append('\n'); System.out.print(out); }}
C#Main.cs · 38 行
using System;using System.Text;class Program{ static string Sign(double slope) { if (slope <= 3) return "平坦"; if (slope <= 7) return "ゆるやか"; if (slope <= 14) return "急"; return "押して歩く"; } static void Main() { int n = int.Parse(Console.ReadLine()); var out_ = new StringBuilder(); int best = 1; double bestSlope = -1; for (int i = 1; i <= n; i++) { string[] p = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); int h = int.Parse(p[0]); int d = int.Parse(p[1]); // int끼리 나누면 몫만 남으므로 double로 바꾼 뒤 나눈다. // 100을 먼저 곱한다: h / d * 100은 7 / 100 * 100 = 7.000000000000001이 된다 double slope = h * 100.0 / d; out_.Append(Sign(slope)).Append('\n'); if (slope > bestSlope) // 같으면 앞 구간을 그대로 둔다 { best = i; bestSlope = slope; } } out_.Append(best).Append('\n'); Console.Write(out_); }}
C++main.cpp · 30 行
#include <iostream>#include <string>std::string sign(double slope) { if (slope <= 3) return "平坦"; if (slope <= 7) return "ゆるやか"; if (slope <= 14) return "急"; return "押して歩く";}int main() { std::ios::sync_with_stdio(false); int n; std::cin >> n; int best = 1; double bestSlope = -1; for (int i = 1; i <= n; i++) { int h, d; std::cin >> h >> d; // int끼리 나누면 몫만 남으므로 double로 바꾼 뒤 나눈다. // 100을 먼저 곱한다: h / d * 100은 7 / 100 * 100 = 7.000000000000001이 된다 double slope = h * 100.0 / d; std::cout << sign(slope) << '\n'; if (slope > bestSlope) { // 같으면 앞 구간을 그대로 둔다 best = i; bestSlope = slope; } } std::cout << best << '\n';}
Cmain.c · 30 行
#include <stdio.h>int main(void) { int n; scanf("%d", &n); int best = 1; double best_slope = -1; for (int i = 1; i <= n; i++) { int h, d; scanf("%d %d", &h, &d); /* int끼리 나누면 몫만 남으므로 double로 바꾼 뒤 나눈다. 100을 먼저 곱한다: h / d * 100은 7 / 100 * 100 = 7.000000000000001이 된다 */ double slope = h * 100.0 / d; if (slope <= 3) { puts("平坦"); } else if (slope <= 7) { puts("ゆるやか"); } else if (slope <= 14) { puts("急"); } else { puts("押して歩く"); } if (slope > best_slope) { /* 같으면 앞 구간을 그대로 둔다 */ best = i; best_slope = slope; } } printf("%d\n", best); return 0;}
Craykonmain.cray · 34 行
n = コンソール.行読み().数に();가장 = 1;가장경사 = -1;繰り返す (i = 1; i <= n; i++){ 구간 = コンソール.数読み(); h = 구간[0]; d = 구간[1]; // 100을 먼저 곱하고 나눈다: h / d * 100은 7 / 100 * 100 = 7.000000000000001이 된다 경사 = h * 100 / d; もし (경사 <= 3) { コンソール.書く("平坦"); } でなければ もし (경사 <= 7) { コンソール.書く("ゆるやか"); } でなければ もし (경사 <= 14) { コンソール.書く("急"); } でなければ { コンソール.書く("押して歩く"); } // 같으면 앞 구간을 그대로 둔다 もし (경사 > 가장경사) { 가장 = i; 가장경사 = 경사; }}コンソール.書く(가장);