7月31号华为试题:
第一题:
# test = "0.50000000000000"
# wantedPrice = float(test)
import numpy as np
n = 10000
wantedPrice = float(input())
maxTotal = int(np.ceil(wantedPrice)) * n
#向上取整
M = int(wantedPrice) * 1
N = 1
for total in range(maxTotal + 1):
floorN = int(np.floor(total / wantedPrice))#向下取整
if floorN != 0 and np.abs(total / floorN -
wantedPrice) < np.abs(M / N - wantedPrice):
M = total
N = floorN
ceilN = int(np.ceil(total / wantedPrice))
if ceilN != 0 and np.abs(total / ceilN -
wantedPrice) < np.abs(M / N - wantedPrice):
M = total
N = ceilN
print(M, N)
第二题:
import java.util.Scanner;
public class huaweiStr {
public static void main(String[] args){
S