結果

問題 No.297 カードの数式
ユーザー yukirinyukirin
提出日時 2016-02-28 19:12:15
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 979 bytes
コンパイル時間 11,295 ms
コンパイル使用メモリ 225,988 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-19 06:28:41
合計ジャッジ時間 12,109 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,820 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 WA -
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,948 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 1 ms
6,940 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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
}
0