题解 | #买苹果#
买苹果
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); } }