Help us understand the problem. What is going on with this article?

# B - ROT N

AtCoder Beginner Contest 146
Aは流石にやらなくていいかな

# 1回目

## 回答

```N = gets.to_i
S = gets.chomp

alf = ['A','B','C','D','E','F','G',
'H','I','J','K','L','M','N','O','P',
'Q','R','S','T','U','V','W','X','Y','Z']

result = ''
for c in S.chars
x = alf.index(c)
x = ( x + N ) % 26
result += alf[x]
end

puts result
```

# 2回目

## 回答

```N = gets.to_i
S = gets.chomp

N.times do |i|
S = S.tr('A-Z', 'B-ZA')
end
puts S
```

# 感想

メモリ使用量9割くらい減ったな。。。

# 追記

コメントを頂いて、もう一回やりました！ありがとうございます！
あと alphabet の頭をとったつもりが alf となっていたのめっちゃ恥ずかしい
(alfabet はポーランド語らしい。へえ〜)

## 回答

```N = gets.to_i
S = gets.chomp
a = [*"A".."Z"]
puts S.tr(a.to_s, a.rotate(N).to_s)
```

## 追記2

`to_s` では配列の文字を繋げられないとのご指摘を頂きました。

```N = gets.to_i
S = gets.chomp
a = [*"A".."Z"]
puts S.tr(a.join, a.rotate(N).join)
```

## 結果

Why not register and get more from Qiita?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away