結果

問題 No.571 3人兄弟(その2)
ユーザー motimoti
提出日時 2018-05-20 16:50:59
言語 Go
(1.22.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 954 bytes
コンパイル時間 13,636 ms
コンパイル使用メモリ 209,292 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 00:04:44
合計ジャッジ時間 12,216 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

// Person ...
type Person struct {
	H    int
	W    int
	Name string
}

// People ...
type People []Person

func (a People) Len() int      { return len(a) }
func (a People) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a People) Less(i, j int) bool {
	if a[i].H == a[j].H {
		return a[i].W < a[j].W
	}
	return a[i].H > a[j].H
}

func main() {
	var vs People
	alphas := []string{"A", "B", "C"}
	for i := 0; i < 3; i++ {
		c := strings.Split(nextLine(), " ")
		x, _ := strconv.Atoi(c[0])
		y, _ := strconv.Atoi(c[1])
		vs = append(vs, Person{
			H:    x,
			W:    y,
			Name: alphas[i],
		})
	}
	sort.Sort(People(vs))
	for _, p := range vs {
		fmt.Println(p.Name)
	}
}
0