結果
問題 |
No.297 カードの数式
|
ユーザー |
![]() |
提出日時 | 2016-03-26 01:35:01 |
言語 | Ruby (3.4.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 792 bytes |
コンパイル時間 | 63 ms |
コンパイル使用メモリ | 7,296 KB |
実行使用メモリ | 18,940 KB |
最終ジャッジ日時 | 2024-10-02 00:50:50 |
合計ジャッジ時間 | 3,497 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 WA * 1 RE * 3 |
コンパイルメッセージ
Main.rb:3: warning: assigned but unused variable - n Syntax OK
ソースコード
class Yukicoder def initialize n = gets.to_i c = gets.chomp.split nums = c.select{|i| i =~ /\d/}.sort.reverse operation = c.select{|i| i =~ /(\+|\-)/}.sort divide_num = operation.size + 1 list = [nums[0..-divide_num].join, nums[-divide_num+1..-1]].flatten if operation.include?('-') puts [eval(list.zip(operation).join), eval(list.reverse.zip(operation).join)].join(' ') else max_val = eval(list.zip(operation).join) nums.reverse! a = Array.new(operation.size+1){""} mod = operation.size + 1 index = 0 while !nums.empty? num = nums.shift a[index%mod] += num index += 1 end min_val = eval(a.join('+')) puts [max_val, min_val].join(' ') end end end Yukicoder.new