年間カレンダー
Posted feedbacks - Erlang
calコマンドっぽく表示します。
> erlc year_cal.erl
> erl -noshell -s year_cal main -s init stop
1月_2008
日 月 火 水 木 金 土
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
(中略)
12月_2008
日 月 火 水 木 金 土
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 | -module(year_cal).
-export([main/0]).
main() -> year_cal(2008).
year_cal(Year) -> lists:foreach(fun manth/1, [{Year, X} || X <- lists:seq(1, 12)]).
manth({Year, Manth}) ->
io:format("~B月_~B~n", [Manth, Year]),
io:format("日 月 火 水 木 金 土~n", []),
First = calendar:day_of_the_week(Year, Manth, 1),
if
7 == First -> true;
true -> io:format(lists:duplicate(((First rem 7) * 3) - 1, " "), [])
end,
manth(Year, Manth, 1).
manth(Year, Manth, Day) ->
case calendar:valid_date(Year, Manth, Day) of
false -> io:nl(); % 一ヶ月の終わり
true ->
Dotw = calendar:day_of_the_week(Year, Manth, Day),
if
7 == Dotw -> io:format("~2B", [Day]); % 日曜日
6 == Dotw -> io:format("~3B~n", [Day]); % 土曜日
true -> io:format("~3B", [Day]) % その他平日
end,
manth(Year, Manth, Day + 1)
end.
|



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 ]