趋势科技第二题
再借借群里老哥的图...
import java.util.Arrays; import java.util.Scanner; public class Main { private static String process(String num1, String num2) { // 坑1:输入转换 String[] strs = num1.split(" "); int[] nums = new int[6]; int num = Integer.parseInt(num2); for (int i = 0; i < strs.length; i++) { nums[i] = Integer.parseInt(strs[i]); } int ans = 0; // 直接暴力.. for (int i = 0; i <= nums[0]; i++) { for (int j = 0; j <= nums[1]; j++) { for (int k = 0; k <= nums[2]; k++) { for (int l = 0; l <= nums[3]; l++) { for (int m = 0; m <= nums[4]; m++) { for (int n = 0; n <= nums[5]; n++) { if (i + 5 * j + 10 * k + 20 * l + 50 * m + n * 100 == num) { ans += i + j + k + l + m + n; } } } } } } } // 如果没有返回 - 1 return ans == 0 ? "-1" : String.valueOf(ans); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); String strValueSequences = sc.nextLine(); String strChargeNum = sc.nextLine(); String sum = process(strValueSequences, strChargeNum); System.out.println(sum); } }#趋势科技##笔试题目##Java#