题解 | #买苹果#

买苹果

https://www.nowcoder.com/practice/61cfbb2e62104bc8aa3da5d44d38a6ef

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int n = in.nextInt();
        in.close();

        int minBags = -1;

        for (int i = 0; i <= n / 6; i++) {
            int remain = n - i * 6;
            if (remain % 8 == 0) {
                int bags = i + remain / 8;
                if (minBags == -1 || bags < minBags) {
                    minBags = bags;
                }
            }
        }
        System.out.println(minBags);
    }
}

全部评论

相关推荐

Elastic90:公司不要求加班,但 又不允许你准点下班,经典又当又立
点赞 评论 收藏
分享
野猪不是猪🐗:我assume that你must技术aspect是solid的,temperament也挺good的,however面试不太serious,generally会feel style上不够sharp
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务