阿里笔试 自测没问题
阿里笔试 求讨论
题目大概意思是:小明去超市消费n次数,若连续两次消费超过10
并且全部消费或部分消费之和为给定数如(500)则可以获得50优惠券
若是可以获得优惠券输出true否则输出false。(不能用循环)
11,13,2.5
500
false
第二题(自测没问题)
import java.util.Arrays;
import java.util.Scanner;
public class Main {
/*请完成下面这个函数,实现题目要求的功能*/
/*当然,你也可以不按照下面这个模板来作答,完全按照自己的想法来 ^-^ */
/******************************开始写代码******************************/
static boolean isExist = false;
public static boolean isQualified (double[] nums, double target) {
if (isTen (nums, 0)) {
isExist = isRed (nums,0 , target);;
};
return isExist;
}
public static boolean isRed (double[] nums,int index , double target) {
if (target==0) {
return true;
}else {
if (index>nums.length-1) {
return false;
}else {
if (isRed (nums,index+1 ,target-nums[index])) {
return true;
}else {
return isRed (nums,index+1 ,target);
}
}
}
}
public static boolean isTen (double[] nums, int index) {
if (nums.length>index+1) {
boolean f = nums[index]>10&&nums[index+1]>10;
if (f) {
return true;
}else {
return isTen (nums,index+1);
}
}else {
return false;
}
}
/******************************结束写代码******************************/
public static void main(String[] args){
Scanner in = new Scanner(System.in);
boolean res;
double[] j;
String str = in.nextLine().trim().toString();
j = Arrays.stream(str.split(",")).mapToDouble(Double::parseDouble).toArray(); //java8 only
double k;
k = Double.parseDouble(in.nextLine().trim());
res = isQualified (j, k);
System.out.println(String.valueOf(res));
}
}
#阿里巴巴##笔试题目#
