complete 1541.py 10828.py 11399.py
This commit is contained in:
1 parent
fbdd0cdc51
commit
fa03328a2f
3 files changed
+55
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import sys
|
||||
|
||||
|
||||
class Stack(list):
|
||||
def push(self, *args, **kwargs):
|
||||
self.append(args[0])
|
||||
|
||||
def size(self, *args, **kwargs):
|
||||
return self.__len__()
|
||||
|
||||
def empty(self, *args, **kwargs):
|
||||
return 1 if self.__len__() == 0 else 0
|
||||
|
||||
def top(self, *args, **kwargs):
|
||||
return self.__getitem__(-1)
|
||||
|
||||
def dispatch(self, exp):
|
||||
t = exp.strip().split()
|
||||
try:
|
||||
return self.__getattribute__(t[0])(*map(int, t[1:]))
|
||||
except:
|
||||
return -1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
s = Stack()
|
||||
N = int(sys.stdin.readline())
|
||||
for i in range(N):
|
||||
exp = sys.stdin.readline()
|
||||
ret = s.dispatch(exp)
|
||||
if ret is not None:
|
||||
print(ret)
|
||||
@@ -0,0 +1,12 @@
|
||||
def solve(N, P):
|
||||
P.sort()
|
||||
S = P[0]
|
||||
before = P[0]
|
||||
for p in P[1:]:
|
||||
S += before + p
|
||||
before += p
|
||||
return S
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(solve(int(input()), list(map(int, input().split()))))
|
||||
@@ -0,0 +1,11 @@
|
||||
def solve(exp):
|
||||
t = exp.split("-")
|
||||
S = 0
|
||||
S += sum(map(int, t[0].split("+")))
|
||||
for i in range(1, len(t)):
|
||||
S -= sum(map(int, t[i].split("+")))
|
||||
return S
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(solve(input()))
|
||||
Reference in new issue
Block a user