結果

問題 No.564 背の順
ユーザー ゆうP
提出日時 2024-03-30 02:20:27
言語 Go
(1.23.4)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 720 bytes
コンパイル時間 11,967 ms
コンパイル使用メモリ 242,084 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-09-30 17:24:26
合計ジャッジ時間 12,442 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

// No.564 背の順
package main

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

func main() {
	var h, n int // なま君身長、クラス人数
	fmt.Scan(&h, &n)

	l := make([]int, n)
	l[0] = h
	for i := 1; i < n; i++ {
		fmt.Scan(&l[i])
	}

	sort.Sort(sort.Reverse(sort.IntSlice(l)))
	rank := 0
	for _, v := range l {
		rank++
		if v == h {
			if strings.HasSuffix(strconv.Itoa(rank), "1") {
				fmt.Println(strconv.Itoa(rank) + "st")
			} else if strings.HasSuffix(strconv.Itoa(rank), "2") {
				fmt.Println(strconv.Itoa(rank) + "nd")
			} else if strings.HasSuffix(strconv.Itoa(rank), "3") {
				fmt.Println(strconv.Itoa(rank) + "rd")
			} else {
				fmt.Println(strconv.Itoa(rank) + "th")
			}
			break
		}
	}
}
0