LoginSignup
0
0

More than 3 years have passed since last update.

AtCoder Problems Training Easy(61~70)

Last updated at Posted at 2020-08-24

目次

1~10
11~20
21~30
31~40
41~50
51~60
61~70 ← 今ココ
71~80
81~90
91~100

61. ABC103 B - String Rotation

Difficulty:151

$\ S_1,S_2 \dots S_N\ $を$\ S_2 \dots S_N,S_1\ $、$\ \dots S_N,S_1,S_2\ $と順番に回転させて、$\ S=T\ $になるか調べる。

s = list(input())
t = list(input())
for i in range(len(s)):
    if s == t:
        print('Yes')
        exit(0)
    a = s[0]
    s.pop(0)
    s.append(a)
print('No')

62. ABC049 B - たてなが

Difficulty:152

入力された画像の行を 2 回ずつ出力すればいい。

h,w = map(int,input().split())
c = [input() for i in range(h)]
for i in range(h):
    print(c[i])
    print(c[i])

63. ABC148 D - Brick Break

Difficulty:164

最終的に$\ 1,2,3 \dots\ $と単調増加になるようにレンガを壊す。
前から$\ s=1\ $かどうか調べ、$\ s=a_i\ $なら次の$\ s+1\ $のレンガを探し、違うならそのレンガは壊す。
壊したレンガが$\ K\ $より多くないか判定する。

n = int(input())
a = list(map(int,input().split()))
s = 1
ans = 0
for i in range(n):
    if a[i] == s:
        s += 1
    else:
        ans += 1
if ans == n:
    print(-1)
else:
    print(ans)

64. ABC058 B - ∵∴∵

Difficulty:172

$\ O_1,E_1,O_2,E_2 \dots\ $の順に文字を結合し、パスワードを復元する。
文字列の長さが$\ O\ $が$\ E\ $より 1 長くなることがあるので注意する。

o = input()
e = input()
ans = []
for i in range(len(e)):
    ans.append(o[i])
    ans.append(e[i])
if len(o) > len(e):
    ans.append(o[-1])
print(''.join(ans))

65. ABC053 B - A to Z String

Difficulty:177

文字列$\ s\ $の中から一番左にある$\ A\ $と、一番右にある$\ Z\ $の位置を調べ、その差を求める。

s = input()
a = s.find('A')
z = s.rfind('Z')
print(z-a+1)

66. AGC003 A - Wanna go back home

Difficulty:164

$\ N,W,S,E\ $の数を数える。
移動する距離は自由なので、$\ N=S=0\ $または($\ N \neq 0\ $かつ$\ S \neq 0\ $)なら縦の座標は家と同じになる。
同じように$\ W,E\ $も判定し、両方とも条件を満たせば Yes になる。

l = list(input())
n = l.count('N')
w = l.count('W')
s = l.count('S')
e = l.count('E')
if n == s or (n != 0 and s != 0):
    if w == e or (w != 0 and e != 0):
        print('Yes')
        exit(0)
print('No')

67. ABC155 C - Poll

Difficulty:197

$\ S\ $が何回登場したか数えておき、最大の登場回数も求めておく。
$\ S\ $の重複をなくしてソートし、$\ S_i\ $の登場回数が最大なら出力する。

import collections
n = int(input())
s = list(input() for i in range(n))
c = collections.Counter(s)
p = max(c.values())
s = sorted(list(set(s)))
for i in range(len(s)):
    if c[s[i]] == p:
        print(s[i])

68. ABC128 B - Guidebook

Difficulty:301

各レストランの末尾に$\ 1 \dots N\ $の番号を追加しておく。
その後、レストランの市をキーにしてソートし、同じ市内のレストランで点数をキーにソートし、順番に番号を答える。

n = int(input())
l = []
for i in range(1,n+1):
    s,p = input().split()
    t = [s,int(p),i]
    l.append(t)
l.sort()
def check(m,i):
    z = list(l[m:i])
    z.sort(key = lambda x: x[1] , reverse = True)
    for j in range(i-m):
        print(z[j][2])
m = 0
for i in range(1,n):
    if l[m][0] != l[i][0]:
        check(m,i)
        m = i
check(m,n)

69. AGC037 A - Dividing a String

Difficulty:267

$\ K_i \neq K_{i+1}\ $となるように文字列を分割すると、分割する長さは 1 か 2 だけになる。
$\ S_i = S_{i+1}\ $なら$\ S_i,S_{i+1},S_{i+2}\ $ を 1 、 2 に分割、$\ S_i \neq S_{i+1}\ $なら$\ S_i\ $を 1 で分割する。

s = list(input())
i = len(s)
ans = 0
while i >= 3:
    if s[i-1] == s[i-2]:
        i -= 3
        ans += 2
    else:
        i -= 1
        ans += 1
if i <= 1:
    print(ans+i)
else:
    if s[i-1] == s[i-2]:
        print(ans+1)
    else:
        print(ans+2)

70. 三井住友信託銀行プログラミングコンテスト2019 C - 100 to 105

Difficulty:205

$\ \lfloor X/100 \rfloor\ $ で、品物を買える個数$\ N\ $を求める。
下二桁の値段が、$\ N\ $個以内で$\ X\ $と同じになればよい。
$\ 100 \dots 105\ $円の商品が$\ N\ $個以上は買えることが保証されているため、可能な場合$\ X \le N \times 105\ $が成り立つ。

x = int(input())
n = x // 100
if n * 105 >= x:
    print(1)
else:
    print(0)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0