F# AOJ ITP1_6

あんどーなつ
記事: 171
登録日時: 8年前
連絡を取る:

F# AOJ ITP1_6

投稿記事 by あんどーなつ » 8年前

ITP1_6A

CODE:

open System
open System.IO

let r = Console.In
r.ReadLine() // 捨てる
r.ReadLine().Split()
|> Array.rev
|> String.concat " "
|> printfn "%s"
ITP1_6B

CODE:

open System
open System.IO

let r = Console.In
let n = Int32.Parse(r.ReadLine())

let ReadTuple(x) =
    let a = r.ReadLine().Split()
    (a.[0], Int32.Parse(a.[1]))
let cards = Array.init n ReadTuple
            |> Set.ofArray

let complete_cards =
    List.map (fun x -> [("S",x);("H",x);("C",x);("D",x)]) [1..13]
    |> List.concat
    |> Set.ofList

let pic_ord = Map.ofArray([|("S",1);("H",2);("C",3);("D",4)|])
let card_cmp x y =
    if (fst x)  (fst y) then pic_ord.[fst x] - pic_ord.[fst y]
    else (snd x) - (snd y)

let diff =
    Set.difference complete_cards cards
    |> Set.toArray
    |> Array.sortWith card_cmp
for c in diff do
    printfn "%s %d" (fst c) (snd c)

CODE:

open System
open System.IO

let r = Console.In
let p = Int32.Parse
let n = p(r.ReadLine())

let ReadTuple(x) =
    let a = r.ReadLine().Split()
    (p a.[0], p a.[1], p a.[2], p a.[3])
let info = Array.init n ReadTuple

let bld = Array3D.init 4 3 10 (fun _ _ _ -> 0)
for (b, f, r, v) in info do
    Array3D.set bld (b-1) (f-1) (r-1)
                ((Array3D.get bld (b-1) (f-1) (r-1)) + v)
for i in [0..3] do
    for j in [0..2] do
        [| for k in [0..9] -> (Array3D.get bld i j k) |]
        |> Array.map (fun x -> x.ToString())
        |> String.concat " "
        |> printfn " %s"
    if i  3 then printfn "####################"

CODE:

open System
open System.IO

let r = Console.In
let p = Int32.Parse
let (n, m) = r.ReadLine().Split()
             |> fun a -> (p a.[0], p a.[1])

let mat =
    List.init n (fun _ -> r.ReadLine().Split()
                          |> Array.map p
                          |> Array.toList)

let vec = List.init m (fun _ -> p(r.ReadLine()))

let res =
    List.map (fun v -> List.zip v vec
                       |> List.map (fun t -> (fst t) * (snd t))
                       |> List.fold (fun x y -> x+y) 0)
             mat
for num in res do printfn "%d" num
添付ファイル

[拡張子 zip は無効化されているため、表示できません]


コメントはまだありません。