解题思路:
有俩目的,第一是要足够多,第二是要把钱花光。所以直接先全买4,然后看剩多少钱,根据余数把4元的一根笔换做5或6
注意事项:
参考代码:
import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; import java.lang.Math; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); // number of vertices int[] pens = {6,5,4}; int sum = 0; int money = 0; int[] results = new int[3]; sum = n / 4; money = n % 4; if (money == 1){ sum -= 1; results[1] = 1; results[2] = sum; } else if (money == 2){ sum -= 1; results[0] = 1; results[2] = sum; } else if (money == 3){ sum -= 2; results[0] = 1; results[1] = 1; results[2] = sum; } else { results[2] = sum; } System.out.println(results[0] + " " + results[1] + " " + results[2]); } }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:748 |
大神老白 (C语言代码)浏览:690 |
A+B for Input-Output Practice (V) (C语言代码)浏览:640 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:606 |
C语言程序设计教程(第三版)课后习题9.4 (C语言代码)浏览:699 |
1011题解浏览:819 |
关于float,double变量的几点说明浏览:1926 |
敲七 (C++代码)浏览:1119 |
判定字符位置 (C++代码)浏览:733 |
C语言程序设计教程(第三版)课后习题10.4 (C语言代码)浏览:643 |