結果
| 問題 |
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_i
cs = gets.chomp.split
hs = 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 = cs
max = 0
hs['-'].times do
max -= cs[0].to_i
cs = cs.drop(1)
end
hs['+'].times do
max += cs[0].to_i
cs = cs.drop(1)
end
max += cs.reverse.inject (0) { |m, x| m * 10 + x.to_i}
min = 0
if 0 < hs['-']
min += ds[0].to_i
ds = ds.drop(1)
hs['+'].times do
min += ds[0].to_i
ds = ds.drop(1)
end
(hs['-'] - 1).times do
min -= ds[0].to_i
ds = ds.drop(1)
end
min -= ds.reverse.inject (0) { |m, x| m * 10 + x.to_i}
else
ds.reverse.each_with_index do |d, i|
min += d.to_i * 10** (i / (hs['+'] + 1))
end
end
puts "#{max} #{min}"