#TL;DL
paizaの「問題集」をやっていたら、Pythonの解答サンプルが用意されていないものがおおく、また作成した解答も保存されないため、備忘として自分が作成したスクリプトを保存していく。
#静的メンバ
###STEP: 1 クラスの作成
class employee:
members = []
def __init__(self):
pass
def make(self, number, name):
member = {
'number':number
,'name':name
}
self.members.append(member)
def getnum(self,number):
return self.members[number-1]['number']
def getname(self,number):
return self.members[number-1]['name']
n = int(input())
empobj = employee()
for _ in range(n):
inp = input().split()
if inp[0] == 'make':
empobj.make(inp[1],inp[2])
elif inp[0] == 'getnum':
print(empobj.getnum(int(inp[1])))
elif inp[0] == 'getname':
print(empobj.getname(int(inp[1])))
###STEP: 2 コンストラクタ
class employee:
def __init__(self,number,name):
self.number = number
self.name = name
def getnum(self):
return self.number
def getname(self):
return self.name
members = [employee(0,'init')]
n = int(input())
for _ in range(n):
array = input().split()
if array[0] == 'make':
members.append(employee(array[1], array[2]))
elif array[0] == 'getnum':
print(members[int(array[1])].getnum())
elif array[0] == 'getname':
print(members[int(array[1])].getname())
###STEP: 3 クラスのメンバの更新
class employee:
def __init__(self,number,name):
self.number = number
self.name = name
def getnum(self):
return self.number
def getname(self):
return self.name
def change_num(self,new_number):
self.number = new_number
def change_name(self,new_name):
self.name = new_name
members = [employee(0,'init')]
n = int(input())
for _ in range(n):
inputs = input().split()
if inputs[0] == 'make':
_number = int(inputs[1])
_name = inputs[2]
members.append(employee(_number,_name))
elif inputs[0] == 'getnum':
_number = int(inputs[1])
_member = members[_number]
print(_member.getnum())
elif inputs[0] == 'getname':
_number = int(inputs[1])
_member = members[_number]
print(_member.getname())
elif inputs[0] == 'change_num':
_number = int(inputs[1])
_new_number = inputs[2]
_member = members[_number]
_member.change_num(_new_number)
elif inputs[0] == 'change_name':
_number = int(inputs[1])
_new_name = inputs[2]
_member = members[_number]
_member.change_name(_new_name)
###STEP: 4 クラスの継承
class Minurs:
def __init__(self):
self.total = 0
self.alcohol_ordered = False
def order_food(self,price):
self.total += price
def order_softdrink(self,price):
self.total += price
def order_alcohol(self,price):
pass
def print_total(self):
print(self.total)
class Adults(Minurs):
def order_alcohol(self,price):
self.total += price
self.alcohol_ordered = True
def order_food(self,price):
if self.alcohol_ordered:
self.total += price -200
else:
self.total += price
# Start
counts,orders = map(int, input().split())
customers = []
for _ in range(counts):
old = int(input())
if old < 20:
customers.append(Minurs())
else:
customers.append(Adults())
for _ in range(orders):
idx, order_ptn, price = input().split()
idx = int(idx)
price = int(price)
cust = customers[idx - 1]
if order_ptn == 'food':
cust.order_food(price)
elif order_ptn == 'softdrink':
cust.order_softdrink(price)
elif order_ptn == 'alcohol':
cust.order_alcohol(price)
for customer in customers:
customer.print_total()
###STEP: 5 デフォルト引数
class Minurs:
def __init__(self):
self.total = 0
self.alcohol_ordered = False
def calc_order(self,order_ptn,price=500):
if order_ptn == 'alcohol' or order_ptn == '0':
pass
else:
self.total += price
def print_total(self):
print(self.total)
class Adults(Minurs):
def calc_order(self,order_ptn,price=500):
if order_ptn == '0' or order_ptn == 'alcohol':
self.total += price
self.alcohol_ordered = True
elif order_ptn == 'food' and self.alcohol_ordered == True:
self.total += price -200
else:
self.total += price
# Start
counts,orders = map(int, input().split())
customers = []
for _ in range(counts):
old = int(input())
if old < 20:
customers.append(Minurs())
else:
customers.append(Adults())
for _ in range(orders):
recept = list(input().split())
idx = int(recept[0])
order_ptn = recept[1]
cust = customers[idx - 1]
if recept[1] == '0':
cust.calc_order(order_ptn)
else:
price = int(recept[2])
cust.calc_order(order_ptn, price)
for customer in customers:
customer.print_total()
###Final: 静的メンバ
class Minurs:
def __init__(self):
self.total = 0
self.alcohol_ordered = False
def calc_order(self,order_ptn,price=500):
if order_ptn == 'alcohol' or order_ptn == '0':
pass
else:
self.total += price
def print_total(self):
print(self.total)
class Adults(Minurs):
def calc_order(self,order_ptn,price=500):
if order_ptn == '0' or order_ptn == 'alcohol':
self.total += price
self.alcohol_ordered = True
elif order_ptn == 'food' and self.alcohol_ordered == True:
self.total += price -200
else:
self.total += price
class Closed:
static_closed = 0
# Start
counts,orders = map(int, input().split())
customers = []
for _ in range(counts):
old = int(input())
if old < 20:
customers.append(Minurs())
else:
customers.append(Adults())
for _ in range(orders):
recept = list(input().split())
idx = int(recept[0])
order_ptn = recept[1]
cust = customers[idx - 1]
if recept[1] == '0':
cust.calc_order(order_ptn)
elif recept[1] == 'A':
cust.print_total()
Closed.static_closed += 1
else:
price = int(recept[2])
cust.calc_order(order_ptn, price)
print(Closed.static_closed)
#ロボットの暴走
###STEP: 1 出口のない迷路
branches,choices,start = map(int,input().split())
roots = [[0]]
for _ in range(branches):
roots.append(input().split())
recent = roots[int(start)]
answer = recent[0]
for _ in range(choices):
choice = int(input())
recent = roots[int(recent[choice])]
answer += recent[0]
print(answer)
###STEP: 2 RPG
class Hero:
def __init__(self,l,h,a,d,s,c,f):
self.level = l
self.hp = h
self.atk = a
self.defe = d
self.speed = s
self.wise = c
self.fortune = f
def levelup(self,h,a,d,s,c,f):
self.level += 1
self.hp += int(h)
self.atk += int(a)
self.defe += int(d)
self.speed += int(s)
self.wise += int(c)
self.fortune += int(f)
def muscle_training(self,h, a):
self.hp += int(h)
self.atk += int(a)
def running(self,d, s):
self.defe += int(d)
self.speed += int(s)
def study(self,c):
self.wise += int(c)
def pray(self,f):
self.fortune += int(f)
def print_status(self):
print(f'{self.level} {self.hp} {self.atk} {self.defe} {self.speed} {self.wise} {self.fortune}')
heros =[]
entry,events = map(int, input().split())
#勇者初期データ登録
for _ in range(entry):
l,h,a,d,s,c,f = list(map(int,input().split()))
heros.append(Hero(l,h,a,d,s,c,f))
#各種イベント
for _ in range(events):
event = input().split()
hero_number = int(event[0])
event_name = event[1]
hero = heros[hero_number-1]
if event_name == 'levelup':
hero.levelup(event[2],event[3],event[4],event[5],event[6],event[7])
elif event_name == 'muscle_training':
hero.muscle_training(event[2],event[3])
elif event_name == 'running':
hero.running(event[2],event[3])
elif event_name == 'study':
hero.study(event[2])
elif event_name == 'pray':
hero.pray(event[2])
for x in heros:
x.print_status()
###STEP: 3 格闘ゲーム
###STEP: 4 スーパースーパースーパーカー
###Final: ロボットの暴走