牛客--2019网易--访友

题目描述:
小易准备去拜访他的朋友,他的家在0点,但是他的朋友的家在x点(x > 0),均在一条坐标轴上。小易每一次可以向前走1,2,3,4或者5步。问小易最少走多少次可以到达他的朋友的家。
输入描述:
一行包含一个数字x(1 <= x <= 1000000),代表朋友家的位置。
输出描述:
一个整数,最少的步数。
输入:
4
10
输出:
1
2
题意:
题目描述
题解
分情况讨论,能mod5的和不能的
代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;

int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        int ans = 0;
        if(n % 5 == 0) ans = n / 5;
        else{
            ans = n / 5;
            ans ++;
        }
        printf("%d\n",ans);
    }
    return 0;
}
发布了228 篇原创文章 · 获赞 1 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/Ypopstar/article/details/105159604
今日推荐