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 } // +++++++++++++++++++++++++++++