Skip to content

Instantly share code, notes, and snippets.

@zaki
Created December 6, 2013 03:57
Show Gist options
  • Save zaki/7818337 to your computer and use it in GitHub Desktop.
Save zaki/7818337 to your computer and use it in GitHub Desktop.
新人女子の書いたコードを直すだけの簡単なお仕事です!
# https://paiza.jp/poh/ec-campaign
n, d = STDIN.gets.split(/ /).map(&:to_i)
products = []
1.upto(n) do |i|
products << STDIN.gets.to_i
end
campaigns = []
1.upto(d) do |m|
campaigns << STDIN.gets.to_i
end
0.upto(d-1) do |c|
campaign_price = campaigns[c]
File.open("test_case_#{c}.rb", "w") do |out|
0.upto(n-1) do |i|
0.upto(n-1) do |j|
next if j == i
out.write("item_#{i}_#{j} = #{products[i] + products[j]} # #{i} + #{j} の価格\n")
end
end
0.step(campaign_price-10, 10) do |step|
0.upto(n-1) do |i|
0.upto(n-1) do |j|
next if j == i
out.write(%(if item_#{i}_#{j} == #{campaign_price - step}\n))
out.write(%( print "#{i+1}と#{j+1}の組み合わせ#{step == 0 ? "が最大!" : "は-#{step}円差でおしい!"}"\n))
out.write(%( exit\n))
out.write(%(end\n))
end
end
end
out.write(%(print "0円で残念"\n))
end
end
__END__
新人女子さん、不安で夜も眠れないと聞いて助けて上げたいです。
コードは根本的に間違ってたんですね。手で書くととても間に合わないので
上記のコードでコードを作ればもっと早く書けますね。ま、まだ
先輩達の効率がいいやり方に付いて色々勉強することが多いと思いますけど
何卒これからもよろしくおねがいします。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment