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?

問題概要

英小文字からなる文字列Sが与えられる。'a', 'i', 'u', 'e', 'o'を取り除いた文字を出力する。

解法と実装

for文を使って、順番に文字を見ることで判定ができます。
end=""をつけることで、出力が改行されません。

S = input()
for s in S: # Sの文字を順番にsとして見る
  if (s in ['a', 'i', 'u', 'e', 'o']): # sが右の配列の中にある時
    continue # このfor文内の後ろのコードは実行されない
  print(s, end="") # continueされない、すなわち母音でない時出力

replaceを使うことで、特定の文字を入れ替えることができます。

S = input()
S = S.replace('a','') # 'a'という文字を''(何もない)に変える
S = S.replace('e','')
S = S.replace('i','')
S = S.replace('o','')
S = S.replace('u','')
print(S)
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?