年間カレンダー
Posted feedbacks - Scheme
Gauche で書いてみました。
出力部が意外と長くなってしまった。
出力例:
<< 2007/1 >>
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 [ 6]
< 7> 8 9 10 11 12 [13]
<14> 15 16 17 18 19 [20]
<21> 22 23 24 25 26 [27]
<28> 29 30 31
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | (use srfi-1)
(use srfi-19)
(use gauche.collection)
(use gauche.sequence)
(define (show-calendar n)
(define (leap-year? n)
(or (zero? (modulo n 400))
(and (zero? (modulo n 4))
(not (zero? (modulo n 100))))))
(define week-days
(circular-list 0 1 2 3 4 5 6))
(define (make-calendar)
(map (lambda (month days)
(let ((m (date-week-day (make-date 0 0 0 0 1 month n 0))))
(append (make-list m #f) (take (drop week-days m) days))))
(iota 12 1)
`(31 ,(if (leap-year? n) 29 28) 31 30 31 30 31 31 30 31 30 31)))
(for-each-with-index
(lambda (i ws)
(format #t " << ~A/~A >>~%" n (+ i 1))
(format #t "Sun Mon Tue Wed Thu Fri Sat~%")
(let loop ((ws ws) (d 1))
(cond
((null? ws)
(format #t "~%~%"))
((not (car ws))
(format #t " ")
(loop (cdr ws) d))
(else
(format #t (case (car ws)
((0) "<~2@A> ")
((6) "[~2@A]~%")
(else " ~2@A "))
d)
(loop (cdr ws) (+ d 1))))))
(make-calendar)))
(define (main args)
(show-calendar (string->number (cadr args))))
|


186
#4884()
Rating4/4=1.00
nを入力としてn年の年間カレンダーを返すプログラムを作ってください 少なくとも日曜日と土曜日が判別出来るようにしてください 出力は標準出力でもファイルでも構いません デザインは各自のお好みで 出力例1: (y-calendar 2008)=> #=Saturday, @=Sunday 2008/1 1 2 3 4 #5 @6 7 ... 2008/2 1 #2 @3 4 5 6 7 ... ... 2008/12 1 2 3 4 5 #6 @7 ... 出力例2: (y-calendar 2008)=> M T W T F S S M 2008/ 1 1 2 3 4 5 6 7 ... 2008/ 2 1 2 3 4 ... ... 2008/12 1 2 3 4 5 6 7 8 ... 出力例3: (y-calendar 2008)は2008.htmlを出力する 2008.htmlの中身 ---- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>2008 calendar</title> <style type="text/css"> * {font-family: monospace;} span {margin: 0px 3px;} span.sunday {color:red;font-weight:bold;} span.saturday {color:blue;font-weight:bold;} dd ul li{display:inline;} </style> </head> <body> <h1>2008 calendar</h1> <dl> <dt>2008/1</dt> <dd><ul> <li><span class="weekday">1</span></li> <li><span class="weekday">2</span></li> <li><span class="weekday">3</span></li> <li><span class="weekday">4</span></li> <li><span class="saturday">5</span></li> <li><span class="sunday">6</span></li> ... </ul></dd> ... </dl> </body> </html> ----[ reply ]