贴个第一题吧,第三题没ac,在线蹲一个大哥吧 public static int numberofprize (int a, int b, int c) { // write code here List<Integer> list = new ArrayList<>(); list.add(a); list.add(b); list.add(c); Collections.sort(list); int max = list.get(2); int med = list.get(1); int min = list.get(0); if(max - med >= (med - min) *2){ max -= 2 * (med - min); int temp = Math.max((max - med) / 5,0); return temp + med; }else{ min = (max - med) / 2 + min; return (min + med) / 2; } }
C++ 代码 void reward() { vector<int> nums(3); for (int i = 0; i < 3; ++i) cin >> nums[i]; sort(nums.begin(), nums.end()); int res = nums[0]; for (int i = 0; i < 3; ++i) nums[i] -= res; if (nums[1] == 0) { res += nums[2] / 5; } else { res += (nums[1] + nums[2]) / 4; } cout << res << endl; }