Codeforces 617A 大象 – 翻譯與解答

難易度 : 800

英文原文如下

An elephant decided to visit his friend. It turned out that the elephant’s house is located at point 0 and his friend’s house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend’s house.

中文翻譯

一隻大象決定要拜訪他的朋友。他的房子位於點0,他的朋友的房子座標位於點x(x > 0) 。大象一步可以移動1到5的距離。判斷他要到達他朋友家需要的最少步數。

輸入

The first line of the input contains an integer x (1 ≤ x ≤ 1 000 000) — The coordinate of the friend’s house.

第一行輸入包含了一個整數 x (1 ≤ x ≤ 1 000 000) – 朋友房子的座標

輸出

Print the minimum number of steps that elephant needs to make to get from point 0 to point x.

印出大象從 點0 移動到 點x 需要的最少步數

範例

輸入5
輸出1
輸入12
輸出3

解題思路

到朋友家,然後一步可以走1到5的距離,那我當然沒問題的話都走5啊! 毫無疑問的吧

故寫起來也挺容易的,判斷是否能被5整除,若不行則加上一步就好!

C#解決方案

方案1

int n = int.Parse(Console.ReadLine());
int res = n/5+(n%5==0?0:1);

Console.WriteLine(res);

Java解決方案

方案1

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        
        System.out.println(n/5+(n%5==0?0:1));
        
    }
}

結論

超EASY的一題,快樂的水了一篇文章

🧡如果這篇文章有幫上你的一點點忙,那是我的榮幸

🧡收藏文章或幫我點個廣告,那都是對我的支持

✅如有任何疑問,歡迎透過留言或messenger讓我知道 !

題目連結 : Problem – 617A – Codeforces

一些其他的文章

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *