Skip to content

Instantly share code, notes, and snippets.

View hamuhei1412's full-sized avatar

hamuhei1412 hamuhei1412

View GitHub Profile
@hamuhei1412
hamuhei1412 / ABC049C.rb
Last active March 21, 2018 15:17
ABC049C
str = gets
str.chomp!
str.reverse!
a = 0
while a < str.size
result = true #これがループ終了時に真ならNo
s = 0 #次にワープする文字数
if a+5 <= str.size #配列外参照を危惧
if str[a,5] == "maerd"||str[a,5] == "esare" #5文字とった時にどちらかに当てはまればセーフ
result = nil
@hamuhei1412
hamuhei1412 / ABC085.rb
Last active March 21, 2018 15:02
ABC085B
a = gets.to_i
AR = Array.new
a.times{AR << gets.to_i} #a行に渡る配列を取得
AR.uniq! #重複要素を削除
puts AR.size
@hamuhei1412
hamuhei1412 / ABC083.rb
Last active March 21, 2018 14:54
ABC083B
N,A,B = gets.split.map(&:to_i) #N,A,Bを取得
ans = 0
def calu(n) #各桁の和を計算する関数を宣言
a = n #rubyの関数の仕様を把握してないので一応
@i = 0 #各桁の和を代入する変数
while a >= 10 #各桁の和を求める
@i += a%10
a /= 10
end
@i += a%10 #1桁の数を拾うために
@hamuhei1412
hamuhei1412 / ABC081B.rb
Last active March 21, 2018 14:45
ABC081B
N = gets.to_i #配列のサイズを取得(特にこのあと使わないけど)
ar = gets.split.map(&:to_i) #空白区切りの配列を取得
ans = 1000000000 #答えの変数を大きい値で初期化
for moke in ar do #配列の中の要素をmokeに入れてぶん回す
s = 0 #mokeが2で割れる回数を0で初期化
while moke%2==0 do #このループ内でmokeが2で割れる回数を求める
moke /= 2
s += 1
end
moke = gets #文字列を取得
puts moke.count("1") #.countの引数に"1"を指定することで、1の数を出力
@hamuhei1412
hamuhei1412 / ABC086.rb
Last active March 21, 2018 14:40
ABC086A
a,b=gets.split.map(&:to_i) #空白区切りの整数を取得
puts((a*b)%2==0 ? "Even" : "Odd") #かけた値の偶奇を判定