解题思路:
注意事项:先取100面额的人民币,再依次降低面额
参考代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
int[] a = new int[100];// 定义一个长度为100的整形数组
int x = sc.nextInt();
if (x == 0)
break;
else
for (int i = 0; i < x; i++) {
a[i] = sc.nextInt();
} // 输入数组的值
System.out.println(gs(a, x));// 调用方法求出最少需要的人民币张数
}
}
public static int gs(int[] a, int x) {
int s = 0;
for (int i = 0; i < x; i++) {
s = s + a[i] / 100 + a[i] % 100 / 10 + a[i] % 10 / 5 + a[i] % 5 / 2 + a[i] % 2 / 1;// 先去最大面额的人民币,依次递减,直到结束
}
return s;
}
}