結果

問題 No.39 桁の数字を入れ替え
ユーザー 第一のいっちー第一のいっちー
提出日時 2020-07-15 11:53:10
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 1,638 bytes
コンパイル時間 11,389 ms
コンパイル使用メモリ 235,628 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2024-05-01 10:10:47
合計ジャッジ時間 12,172 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

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

func main() {
	num := readInt()

	// ゴリ押し
	var list []int
	numSlice := digit(num, list)
	// 桁が逆さでsliceにはいるので反対向きに
	numSlice = reverse(numSlice)
	max := 0

	// 1つ目列決定
	for i := 0; i < len(numSlice); i++ {
		// 2つ目列決定
		for j := 0; j < len(numSlice); j++ {
			if i == j {
				continue
			}

			// 数値処理がめんどくさいのでstringで
			// 速さを犠牲に
			tmpNum := ""
			// slice処理用ループ
			for k := 0; k < len(numSlice); k++ {
				// 入れ替え1つ目
				if k == i {
					tmpNum = tmpNum + strconv.Itoa(numSlice[j])
					continue
				}

				// 入れ替え2つ目
				if k == j {
					tmpNum = tmpNum + strconv.Itoa(numSlice[i])
					continue
				}

				// 入れ替え対象列でない時はそのまま
				tmpNum = tmpNum + strconv.Itoa(numSlice[k])

			}
			
			n, _ := strconv.Atoi(tmpNum)
			if n > max {
				max = n
			}
		}
	}

	fmt.Println(max)
}

func digit(i int, list []int) []int {
    if i > 0 {
        return digit(i/10, append(list, i%10))
    }
    return list
}

func reverse(numbers []int) []int {
    for i := 0; i < len(numbers)/2; i++ {
        j := len(numbers) - i - 1
        numbers[i], numbers[j] = numbers[j], numbers[i]
    }
    return numbers
}

// SONODA POWER utliを拝借
// +++++++++++++++++++++++++++++
func readStdin() string {
	in := bufio.NewReader(os.Stdin)
	s, _ := in.ReadString('\n')
	return strings.TrimSuffix(s, "\n")
}

func readInt() int {
	s := readStdin()
	i, _ := strconv.Atoi(s)
	return i
}
// +++++++++++++++++++++++++++++
0