年間カレンダー
Posted feedbacks - C#
これが一番簡単だと思います。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | //http://ja.doukaku.org/119/ 投稿用
using System;
using System.Windows.Forms;
namespace どう書く_org年間カレンダー {
class Program {
[STAThread]
static void Main(string[] args) {
Application.Run(new Form1());
}
}
class Form1:Form {
MonthCalendar calendar = new MonthCalendar();
public Form1() {
int year = int.Parse(Environment.GetCommandLineArgs()[1]);
AutoSize = true;
calendar.Parent = this;
calendar.SetCalendarDimensions(4, 3);
calendar.SelectionStart = new DateTime(year, 1, 1);
}
}
}
|
標準出力へ。
========= 2008/ 1 =========
SUN MON TUE WED THR 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
========= 2008/ 2 =========
SUN MON TUE WED THR 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
......
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | using System;
static class Program {
static void Main(string[] args) {
int year = int.Parse(args[0]);
for(int month = 1; month <= 12; month++) {
int lastday = DateTime.DaysInMonth(year, month);
int week = (int) DateTime.Parse(string.Format("{0}/{1}/1", args[0], month)).DayOfWeek;
Console.WriteLine("========= {0,4}/{1,2} =========", year, month);
Console.WriteLine("SUN MON TUE WED THR FRI SAT");
for(int i = 0; i < week; i++) {
Console.Write(" ");
}
for(int day = 1; day <= lastday; day++) {
Console.Write("{0,3} ", day);
week++;
if (week == 7) {
Console.WriteLine(); week = 0;
}
}
Console.WriteLine();
Console.WriteLine();
}
}
}
|
見た目修正。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | //http://ja.doukaku.org/119/ 投稿用
using System;
using System.Drawing;
using System.Windows.Forms;
namespace どう書く_org年間カレンダー {
class Program {
[STAThread]
static void Main(string[] args) {
Application.Run(new Form1());
}
}
class Form1:Form {
public Form1() {
int year = int.Parse(Environment.GetCommandLineArgs()[1]);
Text = year + " Calender";
MonthCalendar calendar = new MonthCalendar();
calendar.Parent = this;
calendar.Dock = DockStyle.Fill;
calendar.SelectionStart = new DateTime(year, 1, 1);
calendar.SelectionEnd = new DateTime(year, 1, 1);
Size = new Size(calendar.SingleMonthSize.Width * 4, calendar.SingleMonthSize.Height * 3);
}
}
}
|




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 ]