学python嘻嘻,每题第一个是自己的代码,后面的是看见有些好的代码就顺手保存一波了~侵删
import math def isok(X: int,L: int, Z:int)->bool: if(Z>=180) : Z = 360 - Z; if(5*L*1.0 >= math.pi*Z*X/90) : return True return False T = int(input()) while(T): T=T-1 X, L, Z = map(int, input().split()) if(isok(X,L,Z)) : print("YES") else : print("NO")
N = int(input()) flag = False for i in range(2,N+1): for j in range(2,i): for k in range(j,i): for m in range(k,i): if(i*i*i==j*j*j+k*k*k+m*m*m): flag = True print("(%d,%d,%d,%d)"%(i,j,k,m)) if(not flag): print("OMG")
n = int(input()) big, small,tmp =" " c, k, g, t, v, V =0, 0, 0, 0, 25001, -1 for i in range(n): c, k, g, tmp= input().split() t = int(c) * int(k) * int(g) if(t > V) : V, big = t, tmp if(t < v) : v, small =t, tmp print("%s %s"%(big,small))
*******************
n = int(input()) V, big = -1, '' v, small = 25001, '' for i in range(n): arr = input().split() t = int(arr[0]) * int(arr[1]) * int(arr[2]) if(t > V) : V, big = t, arr[3] if(t < v) : v, small =t, arr[3] print("%s %s"%(big,small))
********************
def select(L: list())->int: return L[4] n = int(input()) children = list() for i in range(0,n): temp = input().split(' ') volume = int(temp[0]) * int(temp[1]) * int(temp[2]) temp.append(volume) children.append(temp) children.sort(key = select) print(str(children[n-1][3]) + ' ' + str(children[0][3]))
arr = list(map(int,input().split())) le = len(arr) ans = 0 for i in range(le-1): for j in range(i, le-1): if arr[i]==2*arr[j] or arr[i]*2==arr[j]: ans += 1 print(ans)
********************
arr = list(map(int, input().split())) if arr[-1] == 0: arr.pop() ans = 0 for x in arr: ans += arr.count(2 * x) print(ans)
n = int(input()) if n in range(0, 4): print("infant") elif n in range(4, 13): print("child") elif n in range(13,19): print("youngster") else : print("youth")
def isprime(n: int)->bool: if n==0 or n==1 : return False i = 2 while(i*i<=n): if(n%i == 0): return False i += 1 return True n = int(input()) if(isprime(n)): print("Yes") else: print("No")
n = int(input()) arr = [int(input()) for i in range(n)] arr.sort() print(arr[0])
n = int(input()) f = [0]*(n+2) f[1], f[2] = 1, 1 for i in range(2,n+1): f[i] = f[i-1] + f[i-2] print(f[n])
********************
arr = [0, 1, 1, 2, 3] n = int(input()) for i in range(5, n + 1): arr.append(arr[i - 1] + arr[i - 2]) print(arr[n])
n = int(input()) for i in range(1,n+1): print(i)
n = int(input()) for i in range(3,n+1): if(i%3==0): print(i)
n = int(input()) for i in range(1,n+1): for j in range(1,n-i+1): print(' ',end='') for j in range(1,2*i): print('*',end='') print()
n = input() if '7' in n: print("Yes") else: print("No")
L, R = map(int,input().split()) flag = False for i in range(L,R+1): if '7' in str(i): flag = True print(i) if not flag: print("None")
n = int(input()) print(n) a = [int(input()) for i in range(n)] for i in range(n-1,-1,-1): print(a[i])
********************
n = int(input()) arr = [0] * n for i in range(n): arr[i] = int(input()) print(n) for i in range(1, n + 1): print(arr[-i])
n = int(input()) a = [int(input()) for i in range(n)] a.sort() print("%d %d"%(a[0],a[n-1]))
n = int(input()) print(n) a, sum = [0]*(n+1), [0]*(n+1) for i in range(1,n+1): a[i] = int(input()) sum[i] = sum[i-1] + a[i] print(sum[i])
a, b = map(int, input().split()) if a+b>2147483647 or a+b<-2147483648 : print("Yes") else: print("No")
a, b = map(int, input().split()) print((a|b)-(a&b))
这题是个祸害,题目也没说的很清楚
#include<bits/stdc++.h> using namespace std; int main() { string f;int d; cin>>f>>d; if(f[d+2]>='6') f[d+1]++; else if(f[d+2]=='5') { if(f.size()-2>=d) f[d+1]++; else if((f[d+1]-'0')%2==1) f[d+1]++; } cout<<f.substr(0,2+d); }
n = int(input()) if(n%2==0):print(0) else:print(1)
n = int(input()) a, sum = 0, 0 for i in range(n): s = int(input()) sum += s print(sum)
a, b = map(int, input().split()) for i in range(b, a-1, -1): print(i)
n = int(input()) s = bin(n)[2:] s = s[::-1] print(s)
import math n = int(input()) if ((int(math.sqrt(n)))*(int(math.sqrt(n)))==n): print((int(math.sqrt(n)))) else : print('No')
n, m = map(int, input().split()) sum, t= 0, 0 for i in range(n): t = int(input()) if(t>=m): sum += t print(sum)
n = int(input()) print(bin(n)[2:])
毒瘤题,需要准确表示四舍五入
网上很多所谓准确解决四舍五入的问题很多都是没卵用
其实加偏置值就行了
from decimal import Decimal arr = [eval(i) for i in input().split()] a = 1.2*arr[0] b = 3.5*arr[1] c = 4.5*arr[2] d = 5.0*arr[3] print('{:.1f} {:.1f} {:.1f} {:.1f} {:.1f} '.format(Decimal(a+0.005),Decimal(b+0.005),Decimal(c+0.005), Decimal(d+0.005), Decimal(a+b+c+d+0.005)))
********************
a,b,c,d = map(float, input().split()) aa = 1.2 * a bb = 3.5 * b cc = 4.5 * c dd = 5 * d print(round(aa + 0.01, 1)) print(round(bb + 0.01, 1)) print(round(cc + 0.01, 1)) print(round(dd + 0.01, 1)) print(round(aa+bb+cc+dd + 0.01, 1))
n = int(input()) str = input() ch = input() print(str.find(ch[0]))
S = input() T = input() print(S.find(T))
S = input() T = input() flag = S>T if(flag): print('NO') else: print('YES')
x, y = map(int, input().split()) print(x%y)
a, b, c = map(int, input().split()) print(a * (b + c - a))
x = int(input()) print(x*x+x*2+5)
PI = 3.14159 r = float(input()) print(PI*r*r)
a, b, c = map(int,input().split()) if(a*a+b*b==c*c): print(1) else : print(0)
a, b, c = map(int,input().split()) print(b, c, a)
a, b = map(int,input().split()) if(a+b>10): print(a*b) else: print(a-b)
a, b = map(int,input().split()) if(a+b<0): print('negative') elif(a+b>=4): print('NO') else: print('YES')
ch = input() if(ch=='a'): print('apple') elif(ch=='b'): print('banana') elif(ch=='c'): print('cat') else: print('no')
a, b, c, d = map(int,input().split()) if(a+b>10): print(a*b) elif(b+c>5): print(c*d) elif(d<10 or a*c>100): print('Yes') else: print('No')
a, b = map(int,input().split()) if(a+b==1): print('one') elif(a+b==2): print('two') elif(a+b==3): print('three') elif(a+b==4): print('four') elif(a+b==5): print('five') elif(a+b==6): print('six') elif(a+b==7): print('seven') elif(a+b==8): print('eight') elif(a+b==9): print('nine') else: print('None')
str = bin(int(input()))[2:] idx = str.rfind('1') print(len(str)-idx-1)
n = int(input()) fac = 1 for i in range(1, n+1): fac *= i print(fac)
n = int(input()) arr = [int(i) for i in input().split()] sum = 0 for i in range(n): if(arr[i]<0):break sum += arr[i] print(sum)
N = int(input()) sum = 0.0 for i in range(1,N+1): sum += 1.0/i print(sum)
import math def isprime(n:int)->bool: if(n==1 or n==2): return False for i in range(2, int(math.sqrt(n))+1): if(n%i==0): return False return True N = int(input()) if(isprime(N)): print('yes') else: print('no')
N = int(input()) ret = 0 for i in range(1,N+1): if(i%2==0 or i%3==0 or i%5==0): ret += 1 print(ret)
S = int(input()) if(S>=90 and S<=100): print('A') elif(S>=80 and S<90): print('B') elif(S>=70 and S<80): print('C') elif(S>=60 and S<70): print('D') else: print('E')
num = input() if(num[3]=='0'): num = num[0:3] if(num[2]=='0'): num = num[0:2] if(num[1]=='0'): num = num[0:1] print(num[::-1])
********************
n = int(input()) print(int(str(n)[::-1]))
n = int(input()) for i in range(1,n+1): for j in range(1, i+1): print('%d*%d=%d'%(j, i, j*i), end='') if(j == i): print() else: print(' ',end='')
n = int(input()) for i in range(1,n+1): print(i*'*')
n = int(input()) for i in range(1,n+1): print((2*i-1)*'*')
n = int(input()) sum = 0.0 for i in range(1,n+1): if(i%2==1): sum += 1.0/i else: sum += -1.0/i print(sum)
n = int(input()) sum = 0 for i in range(1, n+1): sum += str(i).count('9') print(sum)
fac = [1, 1, 1*2, 1*2*3, 1*2*3*4, 1*2*3*4*5, 1*2*3*4*5*6, 1*2*3*4*5*6*7, 1*2*3*4*5*6*7*8, 1*2*3*4*5*6*7*8*9, 1*2*3*4*5*6*7*8*9*10] n = int(input()) sum = 0.0 for i in range(1, n+1): sum += 1.0/fac[i] print(sum)
import math def isprime(n:int)->bool: if(n==1 or n==2): return False for i in range(2, int(math.sqrt(n))+1): if(n%i==0): return False return True n = int(input()) for i in range(n-1,1,-1): if(isprime(i)): print(i) exit(0)
n = input() l = len(n) for i in range(l): if(n[i]!=n[-(i+1)]): print('no') exit(0) print('yes')
********************
n = input() s = n[::-1] if n == s: print('yes') else: print('no')
n = int(input()) arr = [int(i) for i in input().split()] sum = 0 for i in range(n): if(arr[i]>0): sum += arr[i] print(sum)
n, m = map(int, input().split()) b = (m-2*n)//2 a = n - b print(a, b)
n, a, b = map(int, input().split()) print(n*(a+b)//(2*a*b), n*(a-b)//(2*a*b))
print(input())
print('My height is %dcm.'%(int(input())))