結果
問題 |
No.297 カードの数式
|
ユーザー |
![]() |
提出日時 | 2015-11-07 23:41:22 |
言語 | Ruby (3.4.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 858 bytes |
コンパイル時間 | 182 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 12,416 KB |
最終ジャッジ日時 | 2024-09-13 14:05:44 |
合計ジャッジ時間 | 3,299 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 WA * 6 |
コンパイルメッセージ
Main.rb:36: warning: assigned but unused variable - n Syntax OK
ソースコード
OP= "+-" def max(s) op = s.take_while {|c| OP.include?(c) } num = s.drop(op.size).reverse v = [] until op.empty? pm = op.pop n = num.pop v.unshift( (pm+n).to_i ) end v.unshift(num.join().to_i) v.inject(0,&:+) end def min(s) op = s.take_while {|c| OP.include?(c) }.reverse num = s.drop(op.size).reverse if op.first == '-' op.shift op.push('+') v = [] until op.empty? pm = op.pop n = num.pop v.unshift( (pm + n).to_i ) end v.unshift(num.join().to_i * -1) v.inject(0,&:+) else mins = Array.new(op.size + 1,"") num.each_with_index {|v, i| mins[i % mins.size] += v } mins.map(&:to_i).inject(0,&:+) end end n = gets.to_i s = gets.split.sort puts [max(s), min(s)].join(" ")