201403-3 命令行选项
usec = input()
use = []
for i in range(0 ,len(usec)):
if 'a' <= usec[i] and usec[i] <= 'z':
if i+1<len(usec) and usec[i+1] == ':':
use.append([usec[i],1])
else:
use.append([usec[i],0])
lines = int(input())
for i in range(0,lines):
sst = ""
inuse = {}
args = input().split(" ")
j = 0
while j+1 < len(args) :
j = j + 1
if args[j][0] == '-':
flag = 0
fflag = 0
for kset in use:
if kset[0] == args[j][1]:
flag = 1
break
if flag:
if kset[1]:
if j+1 >= len(args):
break
else:
for cha in args[j+1]:
if not (('a' <= cha and 'z' >= cha) or ('0' <= cha and '9' >= cha) or cha == '-'):
fflag = 1
if fflag == 1:
break
inuse[args[j]] = args[j+1]
j = j + 1
else:
inuse[args[j]] = 0
else:
break
else:
break
using = [key for key in inuse]
#using = using.sort()
#print(using)
#print(using)
for m in range(0,len(using)):
max = 'a'
maxindex = 0
for n in range(0, len(using)-m):
if using[n][1] > max:
max = using[n][1]
maxindex = n
#print(max,len(using)-m-1,maxindex)
using[len(using)-m-1], using[maxindex] = using[maxindex], using[len(using)-m-1]
print("Case {}: ".format(i+1), end="")
for item in using:
print(item, end=" ")
if inuse[item] != 0:
print(inuse[item], end=" ")
print("")
201409-1 相邻数对
'''
there is a strange bug in CSP system,
which forces me to make a 'try-except' sentence
'''
n = int(input())
num2 = input().split(" ")
num = []
for i in num2:
try:
num.append(int(i))
except:
pass
flag = 0
for i in range(n):
for j in range(i + 1, n):
if abs(num[i] - num[j]) == 1:
flag += 1
print(flag)
201409-2 画图
n = int(input())
allrec = []
maxrec = 0
for i in range(n):
rec = [int(i) for i in input().split(" ")]
maxr = max(rec)
if maxr>maxrec:
maxrec = maxr
allrec.append(rec)
wang = []
#print(allrec)
for i in range(maxrec):
awang = []
for j in range(maxrec):
awang.append(0)
wang.append(awang)
for i in range(n):
for j in range(allrec[i][0], allrec[i][2]):
for k in range(allrec[i][1], allrec[i][3]):
wang[j][k] = 1
flag = 0
for l in wang:
for i in l:
if i==1:
flag += 1
print(flag)
201409-3 字符串匹配
target = input()
ul = int(input())
if ul==0:
target = target.lower()
n = int(input())
chuan = []
for i in range(n):
ss = input()
if ul==0:
chuan.append(ss.lower())
else:
chuan.append(ss)
if chuan[i].count(target) != 0:
print(ss)
201412-1 门禁系统
n = int(input())
#jilu = list(map(int, input().split(" ")))
jilu = input().split(" ")
num = []
for i in jilu:
try:
num.append(int(i))
except:
pass
a = []
for i in range(n+1):
a.append(0)
for item in num:
a[item] += 1
print(a[item],end=" ")
201412-2 Z字型扫描
direc = [[0,1],[1,0]]
mubiao = [[1,-1],[-1,1]]
dirf = 0
mf = 1
n = int(input())
start = [0,0]
ditu = []
for i in range(n):
num3 = input().split(" ")
num = []
for i in num3:
try:
num.append(int(i))
except:
pass
ditu.append(num)
def outs(a):
if n>a[0]>=0 and n>a[1]>=0:
return False
return True
def myp(a,b):
c = [0,0]
c[0] = a[0] + b[0]
c[1] = a[1] + b[1]
return c
imax = 0
print(ditu[start[0]][start[1]],end=" ")
while(start!=[n-1,n-1] and imax<50):
if(start == [0,n-1]):
dirf += 1
if outs(myp(start, mubiao[mf%2])):
start = myp(start, direc[dirf%2])
dirf += 1
mf += 1
else:
start = myp(start, mubiao[mf%2])
print(ditu[start[0]][start[1]],end=" ")
201412-3 集合竞价
import sys
inputs = []
'''
class trade(object):
def __init__(self,sb,price,amount):
self.sb = sb
self.price = price
self.amount = amount
'''
for line in sys.stdin:
line = line.split(" ")
if line[0] == 'cancel':
inputs[int(line[1])-1] = [0,0,0]
inputs.append(line)
l = len(inputs)
buy = []
sell = []
money = []
for line in inputs:
if line[0] == 'buy':
buy.append([float(line[1]),float(line[2])])
money.append(float(line[1]))
if line[0] == 'sell':
sell.append([float(line[1]),float(line[2])])
money.append(float(line[1]))
minamo = 0
bestprice = 0
for s in money:
buyamo = 0
sellamo = 0
for cus in buy:
if cus[0] >= s:
buyamo += cus[1]
for cus in sell:
if cus[0] <= s:
sellamo += cus[1]
nowamo = buyamo if buyamo < sellamo else sellamo
#print(s,buyamo,sellamo)
if nowamo > minamo:
minamo = nowamo
bestprice = s
elif nowamo == minamo and s > bestprice:
minamo = nowamo
bestprice = s
print("{:.2f} {:.0f}".format(bestprice,minamo))