結果
問題 | No.297 カードの数式 |
ユーザー |
|
提出日時 | 2015-11-06 23:29:06 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 90 ms / 1,000 ms |
コード長 | 722 bytes |
コンパイル時間 | 354 ms |
コンパイル使用メモリ | 7,296 KB |
実行使用メモリ | 12,416 KB |
最終ジャッジ日時 | 2024-12-26 02:15:35 |
合計ジャッジ時間 | 3,399 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
コンパイルメッセージ
Main.rb:1: warning: assigned but unused variable - n Syntax OK
ソースコード
n = gets.chomp.to_ics = gets.chomp.spliths = Hash.new(0)cs.map { |c| hs[c] += 1 if c.to_i.to_s != c }cs = cs.select! { |c| c.to_i.to_s == c }.sort!ds = csmax = 0hs['-'].times domax -= cs[0].to_ics = cs.drop(1)endhs['+'].times domax += cs[0].to_ics = cs.drop(1)endmax += cs.reverse.inject (0) { |m, x| m * 10 + x.to_i}min = 0if 0 < hs['-']min += ds[0].to_ids = ds.drop(1)hs['+'].times domin += ds[0].to_ids = ds.drop(1)end(hs['-'] - 1).times domin -= ds[0].to_ids = ds.drop(1)endmin -= ds.reverse.inject (0) { |m, x| m * 10 + x.to_i}elseds.reverse.each_with_index do |d, i|min += d.to_i * 10** (i / (hs['+'] + 1))endendputs "#{max} #{min}"