读了一点《A Byte Of Python》,对python有了初步的认识,但是没有动手练练总是不行的。所以在zoj上找了几道简单题用python写一写:
zoj 1001 A+B Problem
zoj 1001 A+B Problem
题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1001
大意就是输出两个数的和。
import sys
for line in sys.stdin:
a=line.split()
print int(a[0])+int(a[1])
zoj 1048
Financial Management
题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=48
简单的说就是输出平均数。
#import sys
#sys.stdin=open('d:\\in.txt','r') 绝对路径输入输出
#sys.stdout=open('d:\\out.txt','w')
#sys.stdin=open('in.txt','r') 相对路径输入输出
#sys.stdout=open('out.txt','w')
sum=0
for line in range(0,12):
month=raw_input()
sum+=float(month)
print('$%.2f'%(sum*1.0/12))
zoj 1049
I Think I Need a Houseboat
题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=49
大意:每行给出两个数代表自己的坐标,从原点开始侵蚀面积(一个半圆)每一年都会增长50 m^2,问第几年自己的位置会被侵蚀。
#import sys
import math
n=int(raw_input())
for i in range(0,n):
line=raw_input()
lr=line.split()
a=float(lr[0])
b=float(lr[1])
r_2=a*a+b*b
s2=math.pi*r_2/2
s1=50
while(s1<s2):
s1+=50
print('Property %d: This property will begin eroding in year %d.'%(i+1,s1/50))
print('END OF OUTPUT.')
话说回来,代码里没有使用的sys也算compilation error,太严肃了吧。。