LoginSignup
0
2

More than 3 years have passed since last update.

paizaランクCの達成方法(timesメソッド)

Posted at

はじめに

paizaランクCを達成するにはどうすれば良いか?
目安を解説しました。

前提

筆者がRubyを主に学習しているので、Rubyで解説しています。

実行

Cランクを目指すには、繰り返し条件を使いこなす必要があります。
私が良く使うのはtimesメソッドです。


t = gets.to_i

t.times do
  puts "hello!"
end

以上のプログラムを実行すれば、入力した回数だけhello!と出力されます。
応用すれば、次のような事も出来ます。


t = gets.to_i
i = 1

t.times do
  puts i
  i += 1
end

以上プログラムを実行すれば、1から入力され数までの整数が順番に出力されます。
配列も使用できます。


t = gets.to_i
num = []
i = 1

t.times do
  num << i
  i += 1
end

このプログラムを実行すれば、[1, 2, 3, …,i]という配列ができます。

paizaランクCを目指すには、まずはこのtimesメソッドを使いこなすことが必要です。

0
2
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
2