Skip to content

Latest commit

 

History

History
95 lines (75 loc) · 2.01 KB

笔试-作业帮-180925.md

File metadata and controls

95 lines (75 loc) · 2.01 KB

笔试-作业帮-180925

  • 单选 5,填空 5,编程 2,问答 2
  • 编程不允许跳出页面

Index

1. 点对距离

Python(60%)

  • 试了各种情况,不知道哪里有问题
from math import ceil, floor

def foo(ax, ay, bx, by):
    d = ((ax - bx)**2 + (ay - by)**2)**0.5
    #return round(d, 5)
    return d

k = int(input())
n = int(input())

P = []
for _ in range(n):
    x, y = list(map(float, input().split()))
    P.append([x, y])

D = []
for i in range(n):
    for j in range(i+1, n):
        d = foo(P[i][0], P[i][1], P[j][0], P[j][1])
        D.append(d)
        
D.sort()
#print(D)
N = len(D) - 1
#print(N)
#print(ceil(N * (k / 100)))
ans = D[ceil(N * (k / 100))]
#print("%0.5f" % ans)
print(round(ans, 5))
#print(ans)

2. 扩展型表达式求值

Python(57.14%)

  • 不能跳出页面,实在不想写这种题,偷鸡过了 57%
def bar(s):
    while "%" in s:
        i = s.find("%")
        j = i - 1
        while s[j].isdigit():
            j -= 1
        
        s = s[:j+1] + str(int(s[j+1: i]) / 100) + s[i+1:]
    return s
    
def foo(s):
    if "**" in s or "++" in s or "--" in s:
        return "error"
    
    s = bar(s)
    
    try:
        ans = eval(s)
        if isinstance(ans, int):
            return "%d" % ans
        else:
            return "%0.3f" % ans
            #return round(ans, 3)
    except e:
        return "error"

s = input()
ans = foo(s)
#print(bar(s))
print(ans)