結果

問題 No.570 3人兄弟(その1)
ユーザー harhogefooharhogefoo
提出日時 2017-10-14 19:46:34
言語 Go
(1.22.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 954 bytes
コンパイル時間 16,771 ms
コンパイル使用メモリ 222,304 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-08-11 02:35:12
合計ジャッジ時間 12,977 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

func main() {
  numDict := map[string]int{}
  numDict["A"] = nextInt()
  numDict["B"] = nextInt()
  numDict["C"] = nextInt()

  a := List{}
  for k, v := range numDict {
    e := Entry{k, v}
    a = append(a, e)
  }

  sort.Sort(a)
  for _, e := range a {
    fmt.Println(e.name)
  }
}

type Entry struct {
  name string
  value int
}
type List []Entry

func (l List) Len() int {
  return len(l)
}

func (l List) Swap(i, j int) {
  l[i], l[j] = l[j], l[i]
}

func (l List) Less(i, j int) bool {
  // 値が等しい場合はキーで昇順にソート
  if l[i].value == l[j].value {
    return (l[i].name < l[j].name)
  } else {
    return (l[i].value > l[j].value)
  }
}
0