解题思路: 重复使用可使用的最大面值或者相等面值即是最少需要的人民币张数
注意事项:要求可以计算多个工资组
参考代码:
import java.util.ArrayList; import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int[] numa={100,50,10,5,2,1}; ArrayList list =new ArrayList();//存放计数结果 while(true){ int count=0; int n=sc.nextInt(); if (n==0) { //为0结束循环,输出集合 for (Integer integer : list) { System.out.println(integer); } System.exit(0); } int[] num=new int[n]; for (int i = 0; i < num.length; i++) { //存入工资 num[i]=sc.nextInt(); } for (int i = 0; i < num.length; i++) { for (int j = 0; j < numa.length;) { if (num[i]>=numa[j]) { num[i]-=numa[j]; count++; } else if (num[i]==0) { break; } else { //没有合适的面值再降低面值 j++; } } } list.add(count); } } }
0.0分
5 人评分
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:798 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:1430 |
A+B for Input-Output Practice (C语言代码)浏览:468 |
Hello, world! (C语言代码)浏览:824 |
字符串的输入输出处理 (C语言代码)浏览:1009 |
勾股数 (C语言代码)浏览:799 |
C语言程序设计教程(第三版)课后习题12.3 (C语言代码)浏览:548 |
买不到的数目 (C语言代码)浏览:3094 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:646 |
三角形 (C语言代码)浏览:659 |