s=input() a=s.split() avg=0.0 for i inrange(1,6): avg=avg+float(a[i]) avg=avg/5 print(a[0]+": "+'%.4f'%avg)
B
1 2 3 4 5 6 7 8
s=input() s=s.split() if(any(c.isalpha() for c in s[1])): print("Score 1 error!!") elif(any(c.isalpha() for c in s[2])): print("Score 2 error!!") else: print(s[0]+": "+str('%.4f'%((float(s[1])+float(s[2]))/2)))
C
1 2 3 4 5 6
import math as m a=float(input()) b=float(input()) c=float(input()) s=(a+b+c)/2 print('%.2f'%(m.sqrt(s*(s-a)*(s-b)*(s-c))))
D
1 2 3 4 5 6 7 8
import math as m a=float(input()) b=float(input()) c=float(input()) ans1=float('%.2f'%((-b+m.sqrt(b*b-4*a*c))/2*a)) ans2=float('%.2f'%((-b-m.sqrt(b*b-4*a*c))/2*a)) print(ans1 if ans1>ans2 else ans2) print(ans2 if ans1>ans2 else ans1)
III
A
1 2
s=input() print(s.lower().capitalize())
B
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
s=input() s=s.replace('.','!').lower() a=s.split() ans="" for i in a: if(i=="he"or i=="she"): ans=ans+"I" elif(i=="do"or i=="does"): ans=ans+"did" elif(i=="have"or i=="has"): ans=ans+"had" else: ans=ans+i ans=ans+' ' ans=ans.rstrip().capitalize() print(ans)
C
1 2 3 4
import math as m g=9.8 h=float(input()) #sqrt(2h/g)=t print('%.1f'%(m.sqrt(2*h/g)))
D
1 2 3 4 5 6 7 8 9 10 11 12
str=input() str=str.replace('(','{').replace(')','}').lower() str=str.split() meow="" for i instr: if i.startswith("sqrt"): meow=meow+"$\\"+i+"$" else: meow=meow+i meow=meow+' ' meow=meow.capitalize().strip() print(meow)
E
1 2 3 4 5 6
k=[128,64,32,16,8,4,2,1] s=input() ans=0 for i inrange(0,8): ans=ans+k[i] if s[i]=='1'else ans print("The value of binary",s,"in decimal is is:",str(ans)+'.')
l=[] for i inrange(0,3): tmp=float(input()) tmp=tmp*1.25if tmp<60else tmp l.append(tmp) print("PleaseGoToDieOneDie"if (sum(l)/3)<60else"Hmm")
D
1 2 3 4 5 6 7 8 9 10 11 12
import math as m r=int(input()) if r>10000: print("Sleeping in school") else: mn=70 r=r-1500 if r<=0: print(mn) else: mn=mn+(m.ceil(r/500)*5) print(mn)
E
1 2 3 4 5 6
d=[["0101","A"],["0111","B"],["0010","C"],["1101","D"],["1000","E"],["1100","F"]] s=input() s=s.replace(" ","") for x in d: if s==x[0]: print(x[1])
F
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
import sys str=input() ifany(c.isalpha() for c instr): print("-_-") sys.exit() str=int(str) ifstr>100orstr<0: print("Error!") sys.exit() ifstr>=90: print("A\nWork hard play hard") elifstr>=80andstr<90: print("B\nWork hard play hard") elifstr>=70andstr<80: print("C\nWork hard play hard") elifstr>=60andstr<70: print("D\nWork hard play hard") else: print("E\nPlay hard die hard")
G
1 2 3 4 5 6 7 8 9 10 11
s=input() if(s.endswith("tnfsh.tn.edu.tw")): if(s.startswith("https://") or s.startswith("http://")): print("OK!!") else: print("Invalid web site URL!") else: if(s.startswith("https://") and s.endswith("tn.edu.tw")): print("OK!!") else: print("Invalid web site URL!")
V
A
1 2 3 4 5
ans=0.0 n=int(input()) for i inrange(1,n+1): ans=ans+(1/i) print(f'%.4f'%ans)
B
1 2 3 4 5 6 7 8 9 10 11 12 13
import sys defmeow(x): tmp=0 for i inrange(1,x): if(x%i==0): tmp=tmp+i return1if tmp==x else0 a,b=int(input()),int(input()) for i inrange(a,b+1): if(meow(i)): print(i) sys.exit() print("No number is perfect")
C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
s=input() s=s.split() sup=10000 sdn=-1 s=[int(x) for x in s] s.sort(reverse=True) srted="" for i in s: srted=srted+str(i)+' ' srted=srted.strip() for i in s: ifint(i)<60andint(i)>=sdn: sdn=int(i) ifint(i)>=60andint(i)<=sup: sup=int(i) print(srted) print("best case") if sdn>=60or sdn==-1elseprint(sdn) print("worst case") if sup<60or sup==10000elseprint(sup)
D
1 2 3 4 5 6 7 8 9 10 11
import math as m s=input() s=s.split() s=map(int,s) s=list(s) n=len(s) mu=sum(s)/n sig=0.0 for i in s: sig=sig+(i-mu)*(i-mu) print(f'%.3f'%m.sqrt((sig/n)))
E
1 2 3 4 5 6 7 8 9 10
a=input() a=int(a) insu=[] for i inrange(2,a): if a%i==0: insu.append(i) iflen(insu)==0: print("XD") else: print(sum(insu))
VI
A
1 2 3 4 5
s=input().strip() tmp=0 for i in s: tmp=tmp+int(i) print(tmp)
B
1 2 3 4 5 6 7
k=int(input()) s=0 meow=1 while s<=k: s=s+(1/meow) meow=meow+1 print(meow-1)
import math a="" try: while1: s=input() a=a+s+" " except: a=list(map(int,a.split())) sum=0 for i in a: sum=sum+i p=0 f=0 for j in a: if j>=60: p=p+1 else: f=f+1 print(p) print(f) print('{0:.2f}'.format(sum/len(a))) avg=sum/len(a) ss=0 for k in a: ss=ss+k**2 sigma=math.sqrt(ss/len(a)-avg*avg) print('{0:.2f}'.format(sigma))
D
1 2 3 4 5 6 7 8 9 10 11 12 13 14
a=list(map(int, input().split())) i=0 while a[0]!=a[2] or a[1]!=a[2]: i=i+1 b=(a[0]+a[1])//2 if b>a[2]: a[1]=b-1 if b<a[2]: a[0]=b+1 if a[2]==(a[0]+a[1])//2: print(i,': ',b,sep='') print(i+1,': ',a[2],sep='') break print(i,': ',b,sep='')
E
1 2 3 4 5 6 7 8
import sys a=int(input()) tmp=a for i inrange(1,a+1): tmp=tmp-i if tmp<=0: print(i) sys.exit()
F
1 2 3 4 5 6 7 8 9 10 11 12 13
a=input() ans=0 d={} while1: ans=0 for i in a: ans=ans+(int(i)*int(i)) if d.get(ans)==None: d[ans]=1 else: break a=str(ans) print("Happy"if ans==1else"Unhappy")
d=[["0101","A"],["0111","B"],["0010","C"],["1101","D"],["1000","E"],["1100","F"]] t=int(input()) ans="" for _ inrange(0,t): s=input() s=s.replace(" ","") for x in d: if s==x[0]: ans=ans+x[1] print(ans)
B
水題
1 2 3 4 5 6
s=input() a=0;b=0 for i inrange(0,len(s)): a=a+int(s[i]) if i%2==0else a b=b+int(s[i]) if i%2==1else b print(abs(a-b))
C
hint : 簡單的觀念,既然不能判前一項,那就判後一項吧
1 2 3 4 5 6 7 8 9
n=int(input()) a=[int(x) for x ininput().split()] hj=0;lj=0 for i inrange(0,n-1): if a[i]<a[i+1]: hj=hj+1 if a[i]>a[i+1]: lj=lj+1 print(hj);print(lj)
D
hint : 加個輸出不難吧
1 2 3 4 5 6 7 8 9 10 11
meow=int(input()) for k inrange(1,meow+1): n=int(input()) a=[int(x) for x ininput().split()] hj=0;lj=0 for i inrange(0,n-1): if a[i]<a[i+1]: hj=hj+1 if a[i]>a[i+1]: lj=lj+1 print(f"Case {k}:",hj,lj)
E
hint : 先建出一個矩陣,這樣等下輸入時直接塞入就好了,省時間
1 2 3 4 5 6 7 8 9 10 11 12 13 14
x=int(input()) y=int(input()) arr=[[0for i inrange(0,x)] for i inrange(0,y)] for i inrange(0,x): s=input().split() s=s[::-1] ns=0 for j inrange(0,y): arr[j][i]=s[ns] ns=ns+1 for i in arr: for j in i: print(" "*(3-len(str(j)))+str(j),end="") print()
F
hint : 簡單的觀念,輸出時紀錄幾個零,然後再輸出就好啦 !!
1 2 3 4 5 6 7 8 9
s=input().split() zs=0 for i in s: if(i=="0"): zs=zs+1 else: print(i,end=' ') for i inrange(0,zs): print("0",end=' ')
import sys s=input().split();fx=int(s[0]);fy=int(s[1]) s=input().split();x=int(s[0]);y=int(s[1]) d={} d[f"{x}-{y}"]=1 s=input().split() for i in s: if(len(d)>=fx*fy): ans=0 for k in d: ans=ans+int(d[k]) print(ans) sys.exit() if(i=="1"): if(x-1>=0): x=x-1 elif(i=="2"): if(y+1<fy): y=y+1 elif(i=="3"): if(x+1<fx): x=x+1 elif(i=="4"): if(y-1>=0): y=y-1 if(d.get(f"{x}-{y}")==None): d[f"{x}-{y}"]=1 else: d[f"{x}-{y}"]=d[f"{x}-{y}"]+1
VIII
A
hint : 字典
1 2 3 4 5 6 7 8 9 10
import sys str=input() k=str.split() d={} for i in k: d[i]=1if d.get(i)==Noneelse2 for i in k: if d[i]==1: print(i) sys.exit()
B
hint : easy math
1 2 3 4 5 6 7
lst=input() lst=lst.split() pa=int(input()) owo=1 for i in lst: owo=owo*int(i) print(owo%pa)
explain : python 可以執行大數運算所以此題沒什麼意義,正規寫法如下
1 2 3 4 5 6
lst=input().split() pa=int(input()) owo=1 for i in lst: owo=owo*(int(i)%pa) print(owo)
B-2
hint : 簡單的split跟字串基本原理就可以解決
1 2 3 4 5 6 7 8 9 10 11 12 13
s=input().split(',') h=-100000 hn="" sm=0 for i in s: k=i.split(':') if(int(k[1])>h): h=int(k[1]) hn=k[0] sm=sm+int(k[1]) print(i.replace(":"," : ")) print("Sum : "+str(sm)) print("Top : "+hn)
C
hint : 條件判斷,字串處理
1 2 3 4 5 6 7 8 9 10 11 12 13 14
s=input().split() nd=input() w=int(input()) tmp=0 ans="" for i in s: if i==nd: tmp=tmp+1 if(tmp!=w): ans=ans+i+' ' else: ans=ans+i ans=ans+' ' print(ans.strip())
s=set() d={} h=0 l=0 try: while1: st=input() st=st.strip() st=st.split(',') for i in st: if (i in s)==False: s.add(i) if d.get(i)==None: d[i]=1 else: d[i]=d[i]+1 l=l+1 except: for i in d.keys(): if(d[i]==l): h=h+1 print(h);print(sorted(s))
E
hint : sorted() 可以依照keys來做排序喔 >\\\<
1 2 3 4 5 6 7 8 9 10 11
s=input().lower() s=s.replace(':','').replace('.','').replace(',','').replace('?','').replace(';','') s=s.split() d={} for i in s: if d.get(i)==None: d[i]=1 else: d[i]=d[i]+1 for i insorted(d.keys()): print(i+":",d[i])
IX
need to know : funtion => def(){}
A
1 2
defsum(a,b): return (int(a)+int(b))
B
1 2 3 4 5 6
defisPrime(a): a=int(a) for i inrange(2,a): if a%i==0: returnFalse returnTrue
C
1 2 3 4 5 6 7 8
defmagic(a): if a=="0": return0 a=int(a) sum=0.0 for i inrange(1,a+1): sum=sum+1/i returnsum
D
1 2 3 4 5 6
deffindMax(s): tmp=-10000 for i in s: ifint(i)>tmp: tmp=int(i) return tmp
E
1 2 3 4 5 6 7 8 9 10 11
defresort(s): zs=0 ans=[] for i in s: if(i=="0"): zs=zs+1 else: ans.append(i) for i inrange(0,zs): ans.append(0) return ans
A
A
1 2 3 4 5 6 7 8 9
defmagic(a): if a=="0": return0 a=int(a) sum=0.0 for i inrange(1,a+1): sum=sum+1/i returnsum print('%.4f'%magic(int(input())))
正規解法:
1 2 3 4 5 6
defmeow(n): if n==1: return1 else: return (1/n)+meow(n-1) print('%.4f'%meow(int(input())))
s=input() s=s.replace('[',' ').replace(']',' ').replace(',',' ') s=s.split() sm=0 for i in s: sm=sm+int(i) print(sm)
正解
1 2 3 4 5 6 7 8 9
defmeow(s,l): for i in l: iftype(i) == type([]): s=meow(s,i) else: s=s+i return s s=eval(input()) print(meow(0,s))
D
1 2 3 4 5 6 7 8 9 10 11 12 13 14
s=list(map(int,input().split())) l=[] l.append(s) while(len(s)>1): a=[] for i inrange(1,len(s)): a.append(s[i]+s[i-1]) s=a l.append(a) for i inrange(len(l)-1,-1,-1): ans="" for j in l[i]: ans=ans+str(j)+' ' print(ans.strip())
遞迴解法 但是非常沒有必要而且時間複雜度很高,p.s.扣還比較長
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
defmeow(s,t): k=[] if(len(s)==t): return s else: for i inrange(1,len(s)): k.append(s[i]+s[i-1]) return meow(k,t)
l=list(map(int,input().split()))
for i inrange(1,len(l)+1): d=meow(l,i) for k inrange(0,len(d)): if k>0 : print(' ',end='') print(d[k],end='') print()