結果
| 問題 |
No.39 桁の数字を入れ替え
|
| コンテスト | |
| ユーザー |
tsuchinaga
|
| 提出日時 | 2019-03-13 08:35:55 |
| 言語 | Go (1.23.4) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 690 bytes |
| コンパイル時間 | 12,043 ms |
| コンパイル使用メモリ | 230,808 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-23 15:56:54 |
| 合計ジャッジ時間 | 12,214 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 WA * 4 |
ソースコード
package main
import (
"fmt"
"strings"
)
func main() {
var s string
_, _ = fmt.Scan(&s)
// 配列にする
nums := strings.Split(s, "")
// 後ろから最大を探す
top := int(nums[0][0] - '0')
max := 0
maxI := -1
for i := len(nums) - 1; i > 0; i-- {
if max < int(nums[i][0]-'0') {
max = int(nums[i][0] - '0')
maxI = i
}
}
if max > top { // 先頭が最大でないなら入れ替える
nums[0], nums[maxI] = nums[maxI], nums[0]
} else if len(nums) >= 2 { // 先頭が最大かつ2番目の数字があるなら、2番目と最大を入れ替える
nums[1], nums[maxI] = nums[maxI], nums[1]
}
for _, v := range nums {
fmt.Print(v)
}
fmt.Println()
}
tsuchinaga