Atcoder備忘録

今まで解いたAtcoderの問題を備忘録として残していきます。
自分の為に残していきます。

## 問題①
https://atcoder.jp/contests/abc270/tasks/abc270_a
```python
a, b = map(int, input().split())
print(a|b)
```
## 問題②
https://atcoder.jp/contests/abc314/tasks/abc314_a
```python
s = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679"
s_index = int(input())
s_index += 1

print(s[:s_index] + s[s_index])
```
## 問題③
https://atcoder.jp/contests/abc271/tasks/abc271_a
```python
n = int(input())
ans = format(n, '#X')
ans_cnt = len(ans)
if ans_cnt == 3:
    print(ans.replace('X', ''))
else:
    print(ans.replace('0X', ''))
```
## 問題④
https://atcoder.jp/contests/abc327/tasks/abc327_b
```python
B = int(input())
flg = False
for i in range(1, 15 + 1):
    ans = i ** i
    if ans == B:
        flg = True
        print(i)
        break
else:
    print(-1)
```
## 問題⑤
https://atcoder.jp/contests/abc327/tasks/abc327_a
```python
N = int(input())
S = input()

if ('ab' in S or 'ba' in S):
    print('Yes')
else:
    print('No')
```
## 問題⑥
https://atcoder.jp/contests/abc305/tasks/abc305_b
```python
p, q = input().split()
al = ['A', 'B', 'C', 'D', 'E', 'F', 'G']
flg = [3, 1, 4, 1, 5, 9]

place_p = al.index(p)
place_q = al.index(q)

if place_p <= place_q:
    ans = sum(flg[place_p:place_q])
    print(ans)
else:
    ans = sum(flg[place_q:place_p])
    print(ans)

```
## 問題⑦
https://atcoder.jp/contests/abc296/tasks/abc296_a
```python
n = int(input())
s = input()
flg = True
cnt = 0
cnt_1 = 0

for i in s:
    if i == 'M':
        cnt += 1
        cnt_1 = 0
    elif i == 'F':
        cnt = 0
        cnt_1 += 1
    if cnt == 2 or cnt_1 == 2:
        flg = False
        break

if flg:
    print('Yes')
else:
    print('No')
```
## 問題⑧
https://atcoder.jp/contests/abc269/tasks/abc269_a
```python
a, b, c, d = map(int, input().split())
ans = (a + b) * (c - d)
ans_1 = 'Takahashi'
print(ans)
print(ans_1)
```
## 問題⑨
https://atcoder.jp/contests/abc294/tasks/abc294_b
```python
n, m = map(int, input().split())
ans = ''
ans_list = []
flg_lst = [chr(ord("A")+i) for i in range(26)] # アルファベット格納
for i in range(n):
    m_list = list(map(int, input().split()))
    for i in m_list:
        if i == 0:
            ans += '.'
        else:
            a = flg_lst[i - 1] # 配列に格納されている文字を取り出しセットする。
            ans += a
    ans_list.append(ans)
    ans = ''

for ans_value in ans_list:
    print(ans_value)

```
## 問題⑩
https://atcoder.jp/contests/abc306/tasks/abc306_b
```python
A = list(map(int, input().split()))
cnt = 0
flg_1 = 0 # 乗数
ans = 0 # 答えを格納
for i in A:
    if i == 1:
        flg_1 = 2 ** cnt
        ans += flg_1
        cnt += 1
    else:
        cnt += 1
print(ans)
```
## 問題⑪
https://atcoder.jp/contests/abc293/tasks/abc293_b
```python
K = int(input())
k_lst = list(map(int, input().split()))
flg_lst = [0] * K
cnt = 0
ans_lst = []
for i in range(1, K + 1):
    ans = k_lst[cnt]
    if flg_lst[i - 1] != 1:
        if not flg_lst[ans - 1] == 1:
            flg_lst[ans - 1] = 1
    cnt += 1
ans = flg_lst.count(0)
print(ans)
print(*[i + 1 for i, x in enumerate(flg_lst) if x == 0]) # iが数値、xが配列の値。
```
## 問題⑫
https://atcoder.jp/contests/abc291/tasks/abc291_a
```python
S = input()
ans = 1
for i in S:
    if i.isupper():
        break
    else:
        ans += 1
print(ans)
```
## 問題⑬
https://atcoder.jp/contests/abc292/tasks/abc292_a
```python
S = input()
ans = S.upper()
print(ans)
```
## 問題⑭
https://atcoder.jp/contests/abc088/tasks/abc088_b
```python
N = int(input())
n_list = list(map(int, input().split()))
n_list.sort()
even = []
odd = []
cnt = 0
for i in n_list:
    if cnt % 2 == 0:
        even.append(i)
        cnt += 1
    else:
        odd.append(i)
        cnt += 1
a_1 = sum(even)
b_1 = sum(odd)
print(abs(a_1 - b_1))


h, w = (int(_) for _ in input().split(" "))

list_ = list()
sum_ax0 = [0 for wi in range(w)]
for hi in range(h):
    line_ = [int(_) for _ in input().split(" ")]
    sum_ax0 = [x + y for x, y in zip(sum_ax0, line_)]
    list_.append(line_)

sum_ax1 = [sum(l) for l in list_]

for hi in range(h):
    vi = [str(sum_ax1[hi] - x + y) for x, y in zip(list_[hi], sum_ax0)]
    print(' '.join(vi))
```
## 問題⑮
https://atcoder.jp/contests/abc283/tasks/abc283_c
```python
S = input()
ans = len(S)
cnt = 0
for i in S:
    if i == '0':
        cnt += 1
    else:
        cnt = 0
    if cnt == 2:
        cnt = 0
        ans -= 1
print(ans)
```
## 問題⑯
https://atcoder.jp/contests/abc286/tasks/abc286_b
```python
N = int(input())
s = input()
cnt = s.count('na')
print(s.replace('na', 'nya', cnt))
```