0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Racketでhackerrankの問題を解いてみる(IO入力)

Posted at

HakcerrankでRacketが使えることに気がついたのでプログラミングの練習がてら何問かといてみた。
問題を解くこと自体はできるけどIO周りがすごく難しかったのでメモ。
もっと良いやり方があればアドバイスくださるとうれしいです。

固定個のデータ(例は2個)

改行でもスペースでもOK。

input.rkt
(define (solve a b)
  (+ a b))

(let ([a (read)]
      [b (read)])
  (printf "~a~%" (solve a b)))

一行取ってリストにする

input.rkt
(define (sum xs)
  (if (empty? xs)
      0
      (+ (car xs) (sum (cdr xs)))))

(let ([xs (map string->number (string-split (read-line)))])
  (printf "~a~%" (sum xs)))

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?