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 1 year has passed since last update.

RubyでAtCoder ABC271(A, B)を解いてみた

Last updated at Posted at 2023-05-01

はじめに

Webエンジニアを目指して、RubyやRailsをいじってます。
今回は、RubyでAtCoder ABC271のA, Bを解きました。備忘録として解き方をまとめていきたいと思います。

A - 484558

a-271.rb
puts gets.to_i.to_s(16).upcase.rjust(2, "0")
別解
puts sprintf("%02X", gets.to_i)

解説

与えられた数字を16進数表記にして、英文字があれば大文字化しています。また、rjustメソッドにより16進表記後の大きさが2となるようにしています。

B - Maintain Multiple Sequences

b-271.rb
n, q = gets.split.map(&:to_i)
array = Array.new(n){ gets.split.map(&:to_i) }
query = Array.new(q){ gets.split.map(&:to_i)}

- q.times do |i|
-  puts array[query[i][0] - 1][query[i][1]]
- end
+ query.each do |factor|
+  puts array[factor[0] - 1][factor[1]]
+ end

0
0
1

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?