結果
| 問題 |
No.39 桁の数字を入れ替え
|
| コンテスト | |
| ユーザー |
tak
|
| 提出日時 | 2019-07-04 15:32:09 |
| 言語 | F# (F# 4.0) |
| 結果 |
AC
|
| 実行時間 | 72 ms / 5,000 ms |
| コード長 | 1,188 bytes |
| コンパイル時間 | 7,323 ms |
| コンパイル使用メモリ | 189,276 KB |
| 実行使用メモリ | 30,976 KB |
| 最終ジャッジ日時 | 2024-09-19 03:57:42 |
| 合計ジャッジ時間 | 9,663 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.fsproj を復元しました (216 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
module Yuki
open System
open System.Text
let solve n =
let num2list n =
(string n).ToCharArray()
|> Array.map (string >> int)
|> Array.toList
let rec list2str (acc : StringBuilder) =
function
| [] -> acc.ToString()
| x :: xs -> list2str (acc.Append(string x)) xs
let rec f (acc : StringBuilder) xs =
match xs with
| [] -> acc.ToString()
| y :: ys ->
let xsMax = xs |> List.max
if y = xsMax then
f (acc.Append(string y)) ys
else
let swapRightIdx =
ys
|> List.indexed
|> List.findBack (fun (_, x) -> x = xsMax)
|> fun (idx, _) -> idx
let ys' =
ys
|> List.mapi (fun i v ->
match i with
| _ when i = swapRightIdx -> y
| _ -> v)
list2str (acc.Append(string ys.[swapRightIdx])) ys'
n
|> num2list
|> f (new StringBuilder())
let N = int <| Console.ReadLine()
solve N
|> Console.WriteLine
tak