试题编号: | 201903-1 |
试题名称: | 小中大 |
时间限制: | 1.0s |
内存限制: | 512.0MB |
1 n=int(input()) 2 3 ans=list(map(int, input().split())) 4 res=[] 5 maxx=max(ans) 6 minn=min(ans) 7 res.append(maxx) 8 res.append(minn) 9 if n%2==0: 10 med=(ans[(n-1)//2]+ans[(n-1)//2+1]) 11 if med%2==0: 12 med=med//2 13 else: 14 med=med/2 15 16 else: 17 med=ans[(n+1)//2-1] 18 19 res.append(med) 20 res.sort(reverse=True) 21 print(‘ ‘.join(map(str, res)))
试题编号: | 201903-2 |
试题名称: | 二十四点 |
时间限制: | 1.0s |
内存限制: | 512.0MB |
1 n=int(input()) 2 3 for _ in range(n): 4 tmp=input() 5 num=[int(tmp[0]),int(tmp[2]),int(tmp[4]),int(tmp[6])] 6 op=tmp[1]+tmp[3]+tmp[5] 7 if (op.count(‘x‘)+op.count(‘/‘)==3) or (op.count(‘+‘)+op.count(‘-‘)==3): #同一优先级,从左往右 8 while op: 9 tmp_p=op[0] 10 if len(op)==1: 11 op=[] 12 else: 13 op=op[1:] 14 if tmp_p==‘x‘: 15 n1=num.pop(0) 16 n2=num.pop(0) 17 num.insert(0,n1*n2) 18 elif tmp_p==‘/‘: 19 n1=num.pop(0) 20 n2=num.pop(0) 21 num.insert(0,n1//n2) 22 elif tmp_p==‘+‘: 23 n1=num.pop(0) 24 n2=num.pop(0) 25 num.insert(0,n1+n2) 26 elif tmp_p==‘-‘: 27 n1=num.pop(0) 28 n2=num.pop(0) 29 num.insert(0,n1-n2) 30 else: # 优先级 31 while op.count(‘x‘): 32 index_x=op.find(‘x‘) 33 op=op[:index_x]+op[index_x+1:] 34 n1=num.pop(index_x) 35 n2=num.pop(index_x) 36 num.insert(index_x,n1*n2) 37 38 while op.count(‘/‘): 39 index_x=op.find(‘/‘) 40 op=op[:index_x]+op[index_x+1:] 41 n1=num.pop(index_x) 42 n2=num.pop(index_x) 43 num.insert(index_x,n1//n2) 44 45 while op.count(‘+‘): 46 index_x=op.find(‘+‘) 47 op=op[:index_x]+op[index_x+1:] 48 n1=num.pop(index_x) 49 n2=num.pop(index_x) 50 num.insert(index_x,n1+n2) 51 52 while op.count(‘-‘): 53 index_x=op.find(‘-‘) 54 op=op[:index_x]+op[index_x+1:] 55 n1=num.pop(index_x) 56 n2=num.pop(index_x) 57 num.insert(index_x,n1-n2) 58 59 if num[0]==24: 60 print(‘Yes‘) 61 else: 62 print(‘No‘)
原文:https://www.cnblogs.com/z-712/p/14619658.html