結果
問題 |
No.297 カードの数式
|
ユーザー |
|
提出日時 | 2016-02-28 19:12:15 |
言語 | Go (1.23.4) |
結果 |
WA
|
実行時間 | - |
コード長 | 979 bytes |
コンパイル時間 | 10,725 ms |
コンパイル使用メモリ | 232,524 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-10 23:09:12 |
合計ジャッジ時間 | 11,912 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 WA * 7 |
ソースコード
package main import ( "bufio" "fmt" "os" "sort" "strconv" ) var sc = bufio.NewScanner(os.Stdin) var rdr = bufio.NewReaderSize(os.Stdin, 1000000) func main() { sc.Split(bufio.ScanWords) n := nextInt() var ns []int var ss []string for i := 0; i < n; i++ { w := nextLine() if w == "+" || w == "-" { ss = append(ss, w) continue } num, _ := strconv.Atoi(w) ns = append(ns, num) } sort.Ints(ns) sort.Strings(ss) big := ns[len(ns)-1] for i := len(ns) - 2; i >= len(ss); i-- { big *= 10 big += ns[i] } max := big for i, ope := range ss { nI := len(ss) - 1 - i switch ope { case "+": max += ns[nI] case "-": max -= ns[nI] } } min := ns[0] ns[len(ss)] = big ns = ns[1:] for i, ope := range ss { switch ope { case "+": min += ns[i] case "-": min -= ns[i] } } fmt.Println(max, min) } func nextLine() string { sc.Scan() return sc.Text() } func nextInt() int { i, _ := strconv.Atoi(nextLine()) return i }