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; 가장경사 = 경사; }}控制台.输出(가장);