結果
問題 | No.297 カードの数式 |
ユーザー |
![]() |
提出日時 | 2016-03-26 01:38:20 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 98 ms / 1,000 ms |
コード長 | 817 bytes |
コンパイル時間 | 323 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 12,288 KB |
最終ジャッジ日時 | 2024-12-26 02:29:12 |
合計ジャッジ時間 | 3,961 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
コンパイルメッセージ
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) a = Array.new(operation.size+1){""} mod = operation.size + 1 index = 0 while !nums.empty? num = nums.pop a[index%mod] = a[index%mod] + num index += 1 end a = a.map{|i| i.to_i(10)} min_val = eval(a.join('+')) puts [max_val, min_val].join(' ') end end end Yukicoder.new