0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

B - Shiritori AtCoder

Last updated at Posted at 2022-05-03

問題

回答


s = int(input()) 
w = [input() for _ in range(s)]

flag = True

if len(w) != len(set(w)):
  flag = False

for i in range(1,s):
  if w[i-1][-1] != w[i][0]:
    flag = False
    
print("Yes" if flag else "No")


ポイント

w[i-1][-1] != w[i][0]:の部分で文字列内のアルファベットを抽出できる。
[-1]で一番後ろの配列を取得できる。
[-2]で後ろから2番目の配列を取得できる。

これが思いつかず。文字列のみの配列でも連想配列的に抽出できることを忘れていた。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?