結果

問題 No.49 算数の宿題
ユーザー MiyamonYMiyamonY
提出日時 2019-09-06 15:27:12
言語 Scheme
(Gauche-0.9.13)
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 767 bytes
コンパイル時間 59 ms
コンパイル使用メモリ 5,376 KB
実行使用メモリ 13,504 KB
最終ジャッジ日時 2023-08-24 17:43:35
合計ジャッジ時間 1,586 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
13,048 KB
testcase_01 AC 23 ms
13,092 KB
testcase_02 AC 24 ms
12,884 KB
testcase_03 AC 27 ms
13,504 KB
testcase_04 AC 25 ms
13,224 KB
testcase_05 AC 23 ms
13,176 KB
testcase_06 AC 23 ms
13,092 KB
testcase_07 AC 23 ms
13,012 KB
testcase_08 AC 23 ms
12,964 KB
testcase_09 AC 23 ms
13,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

(use data.queue)

(let ((s (read-line)))

  (print
   (let loop ((chars (string->list s))
	      (stack (make-queue))
	      (tmp 0))
     (cond ((null? chars)
	    (cond ((queue-empty? stack) (queue-push! stack tmp))
		  (else
		   (let1 op (queue-pop! stack)
			 (queue-push! stack #?=((if (eqv? op #\+) * +) (queue-pop! stack) tmp)))))
	    (queue-pop! stack))
	   (else
	    (let1 char (car chars)
		  (cond ((char-numeric? char)
			 (loop (cdr chars) stack (+ (* 10 tmp) (digit->integer char))))
			(else
			 (cond ((queue-empty? stack) (queue-push! stack tmp))
			       (else
				(let1 op (queue-pop! stack)
				      (queue-push! stack #?=((if (eqv? op #\+) * +) (queue-pop! stack) tmp)))))
			 (queue-push! stack char)
			 (loop (cdr chars) stack 0)))))))))
0