Skip to content

Commit

Permalink
Add: ABC171/{A-E}.py
Browse files Browse the repository at this point in the history
  • Loading branch information
takumiw committed Jun 22, 2020
1 parent b75d524 commit d9823fc
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ABC171/A.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import sys
readline = sys.stdin.readline


def main():
a = readline().rstrip()
if a.lower() == a:
print("a")
else:
print("A")


if __name__ == '__main__':
main()
12 changes: 12 additions & 0 deletions ABC171/B.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import sys
readline = sys.stdin.readline

def main():
N, K = map(int, readline().rstrip().split())
P = list(map(int, readline().rstrip().split()))
P.sort()

print(sum(P[:K]))

if __name__ == '__main__':
main()
31 changes: 31 additions & 0 deletions ABC171/C.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import sys
readline = sys.stdin.readline
alp = "abcdefghijklmnopqrstuvwxyz"


def main():
N = int(readline())
start = 1 # 各範囲でのスタートの値s
cnt = 1 # 文字数
while True:
last = start * 26
if start <= N <= last:
break
start = last + 1
cnt += 1

idx = N - start # その文字数の中で何番目か (0番目スタート)

res = ""
while cnt:
chara = idx // 26 ** (cnt - 1)
idx -= 26 ** (cnt - 1) * chara
chara = alp[chara]
res += chara
cnt -= 1

print(res)


if __name__ == '__main__':
main()
25 changes: 25 additions & 0 deletions ABC171/D.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import sys
readline = sys.stdin.readline
from collections import Counter


def main():
N = int(readline())
A = list(map(int, readline().rstrip().split()))
counter = Counter(A)
res = sum(A)

Q = int(readline())
for _ in range(Q):
b, c = map(int, readline().rstrip().split())
res = res - b * counter[b] + c * counter[b]
counter.setdefault(c, 0)
counter[c] += counter[b]
counter.setdefault(b, 0)
counter[b] = 0

print(res)


if __name__ == '__main__':
main()
39 changes: 39 additions & 0 deletions ABC171/E.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import sys
readline = sys.stdin.readline


def main():
N = int(readline()) # 偶数
A = list(map(int, readline().rstrip().split())) # [自分以外の全ての整数のxor, ...]

if N == 2:
print(*A[::-1])
return

xor = []
for i in range(N-1):
xor.append(A[i] ^ A[i+1]) # a xor b, b xor c, c xor d ...

# bを求める
b = A[0]
for i in range(2, N, 2):
b ^= xor[i]

# aを求める
a = xor[0] ^ b

res = [a, b]
pre = b

# c以降を求める
for x in xor[1:]:
next = pre ^ x
res.append(next)
pre = next


print(*res)


if __name__ == '__main__':
main()
18 changes: 18 additions & 0 deletions ABC171/new_E.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sys
readline = sys.stdin.readline


def main():
N = int(readline()) # 偶数
A = list(map(int, readline().rstrip().split())) # [自分以外の全ての整数のxor, ...]

xor = 0
for a in A:
xor ^= a

res = [a ^ xor for a in A]
print(*res)


if __name__ == '__main__':
main()
File renamed without changes.

0 comments on commit d9823fc

Please sign in to comment.