Skip to content

Instantly share code, notes, and snippets.

View hamuhei1412's full-sized avatar

hamuhei1412 hamuhei1412

View GitHub Profile
@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") #かけた値の偶奇を判定
moke = gets #文字列を取得
puts moke.count("1") #.countの引数に"1"を指定することで、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
@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 / 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 / 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 / ABC085C.rb
Last active March 21, 2018 15:11
ABC085C
Y,N = gets.split.map(&:to_i) #入力
a = 0 #一万円の枚数
while a * 10000 <= N
b = 0 #5000円の枚数
while b * 5000 + a * 10000 <= N
c = (N - (a * 10000 + b * 5000)) / 1000 #1万円の枚数と5000円の枚数が決まれば、考えられる千円札の枚数は一意に決まる。
if(a+b+c==Y&&a*10000+b*5000+c*1000==N) #枚数がYかつ合計金額がNなら出力して終了
puts "#{a} #{b} #{c}"
exit
end
@hamuhei1412
hamuhei1412 / ABC086C.rb
Last active March 21, 2018 15:07
ABC086C
N = gets.to_i
x = []
y = []
t = []
N.times do
line = gets.split.map(&:to_i)
t << line[0]
x << line[1]
y << line[2]
end
@hamuhei1412
hamuhei1412 / ABC087B.rb
Last active March 21, 2018 14:49
ABC087B
A = gets.to_i
B = gets.to_i
C = gets.to_i
X = gets.to_i
#ここまで入力
ans = 0
a = 0 #500円玉の枚数
while a != A+1 do
b = 0 #100円玉の枚数
while b != B+1 do
@hamuhei1412
hamuhei1412 / ABC088B.rb
Last active March 21, 2018 14:57
ABC088B
N = gets.to_i
hoge = gets.split.map(&:to_i)
#ここまで入力
hoge.sort! #小さい順にソート
hoge.reverse! #それを逆順にひっくり返すことによって実質大きい順ソートに
s = 0 #これが偶数の時はAliceの番で、奇数の時はBobの番
Alice = 0
Bob = 0
while s < N
if(s%2==0)