|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
日历.rar
(33.74 KB, 下载次数: 37)
int f (int temp_month, int year, int len1)
{
int month;
int i, j = 0;
int day1;
int k = 1;
for(month = 1; month < temp_month; month++)
{
if((!(year % 4) && (year % 100)) || (!(year % 400)))
{
if(month == 2)
{
day1 = 29;
}
}
else
{
if(month == 2)
{
day1 = 28;
}
}
if(month >= 1 && month <= 7 && month != 2)
{
if(month % 2)
{
day1 = 31;
}
else
{
day1 = 30;
}
}
else if(month >= 8 && month <= 12)
{
if(month % 2)
{
day1 = 30;
}
else
{
day1 = 31;
}
}
for(i = 1; i <= day1; i++)
{
if(i == len1)
{
k = 7;
j = 1;
}
else if(!(k % 7))
{
len1 = i;
}
if(j == 1)
{
k++;
}
}
len1 = 7 - (day1 - len1);
}
return 7 - len1;
}
void panduan (int year, int month, int day)
{
int i;
int j = 0;
int k = 1;
int temp_year;
int len;
int sum = 2;
int temp_day;
int temp_year1;
temp_year1 = year;
temp_day = day;
if((!(year % 4) && (year % 100)) || (!(year % 400)))
{
if(month == 2)
{
day = 29;
}
}
else
{
if(month == 2)
{
day = 28;
}
}
if(month >= 1 && month <= 7 && month != 2)
{
if(month % 2)
{
day = 31;
}
else
{
day = 30;
}
}
else if(month >= 8 && month <= 12)
{
if(month % 2)
{
day = 30;
}
else
{
day = 31;
}
}
/* printf(" Sunday Monday Tuesday Wednesday Thursday Friday Saturday"); */
printf(" S M T W T F S");
printf(" \n");
if(year == 1901)
{
len = 2;
if(month > 1)
{
len = f(month, year, 5);
}
for(i = 0; i < (len * 3); i++)
{
printf(" ");
j++;
}
}
else
{
while(1)
{
year = year - 1;
if((!(year % 4) && (year % 100)) || (!(year % 400)))
{
temp_year = 366;
}
else
{
temp_year = 365;
}
len = temp_year % 7;
sum = sum + len;
if(year == 1901)
{
break;
}
}
if(sum >= 7)
{
sum = sum % 7;
}
if(month > 1)
{
sum = f(month, temp_year1, 7 - sum);
}
for(i = 0; i < (sum * 3); i++)
{
printf(" ");
j++;
}
}
j = 7 - j / 3;
for(i = 1; i <= day; i++)
{
if(i == temp_day)
{
printf("[%d]", temp_day);
}
else
{
printf("%3d", i);
}
if(k == j)
{
printf("\n");
k = 7;
}
else if((!(k % 7) && k))
{
printf("\n");
}
k++;
}
}
# include "stdio.h"
# include "conio.h"
void main()
{
int year, month, day;
int i = 0;
char c;
char ch[2];
char ch1;
s: do
{
i = 0;
printf("\n请输入您要查询的日期 (格式:年-月-日):");
scanf("%d-%d-%d", &year, &month, &day);
ch1 = getchar();
if(ch1 != '\n' || ch1 == 0x20)
{
printf("对不起,输入错误!请重新输入!\n");
i = 1;
while(getchar() != '\n')
{
continue;
}
continue;
}
if((year >= 1901) && (month >= 1 || month <= 12) && (day >= 1 || day <= 31))
{
if((!(year % 4) && (year % 100)) || (!(year % 400)))
{
if(month == 2)
{
if(day > 29)
{
printf("error!\n");
i = 1;
}
}
}
else
{
if(month == 2)
{
if(day > 28)
{
printf("error!\n");
i = 1;
}
}
}
if(month >= 1 && month <= 7 && month != 2)
{
if(month % 2)
{
if(day > 31)
{
printf("error!\n");
i = 1;
}
}
else
{
if(day > 30)
{
printf("error!\n");
i = 1;
}
}
}
else if(month >= 8 && month <= 12)
{
if(month % 2)
{
if(day > 30)
{
printf("error!\n");
i = 1;
}
}
else
{
if(day > 31)
{
printf("error!\n");
i = 1;
}
}
}
}
else
{
printf("对不起,输入错误!请重新输入!\n");
i = 1;
}
if(month < 1 || day < 1)
{
printf("对不起,输入错误!请重新输入!\n");
i = 1;
}
} while (i == 1);
printf("\n\n\n");
printf("%d - %d - %d ", year, month, day);
printf("\n\n");
panduan(year, month, day);
printf("\n\n功能:\n 1.左键:上个月;\n 2.右键:下个月;\n 3.上键:前年;\n 4.下键:明年;\n");
printf(" 5.'+'明天;\n 6.'-'昨天:\n 7.重新查询请按'y';\n");
do
{
for(i = 0; i < 2; i++)
{
*(ch + i) = i;
} //每次都将ch初始化;
*(ch + 1) = getch();
if(*(ch + 1) == -32)
{
*ch = getch();
}
if(*(ch + 1) == 0x2b) //判断是否按下 '+';
{
day++;
if(month == 12 && day > 31)
{
day = 1;
year++;
month = 1;
}
if((!(year % 4) && (year % 100)) || (!(year % 400)))
{
if(month == 2)
{
if(day > 29)
{
month++;
day = 1;
}
}
}
else
{
if(month == 2)
{
if(day > 28)
{
month++;
day = 1;
}
}
}
if(month >= 1 && month <= 7 && month != 2)
{
if(month % 2)
{
if(day > 31)
{
month++;
day = 1;
}
}
else
{
if(day > 30)
{
month++;
day = 1;
}
}
}
else if(month >= 8 && month <= 12)
{
if(month % 2)
{
if(day > 30)
{
month++;
day = 1;
}
}
else
{
if(day > 31)
{
month++;
day = 1;
}
}
}
printf("\n\n\n");
printf("%d - %d - %d ", year, month, day);
printf("\n\n");
panduan(year, month, day);
}
else if(*(ch + 1) == 0x2d) //判断是否按下 '-';
{
day--;
if((!(year % 4) && (year % 100)) || (!(year % 400)))
{
if(month == 3)
{
if(day < 1)
{
month--;
day = 29;
}
}
}
else
{
if(month == 3)
{
if(day < 1)
{
month--;
day = 28;
}
}
}
if(month >= 1 && month <= 7 && month != 2)
{
if(month % 2)
{
if(day < 1)
{
month--;
day = 30;
}
}
else
{
if(day < 1)
{
month--;
day = 31;
}
}
}
else if(month >= 8 && month <= 12)
{
if(month % 2)
{
if(day < 1)
{
month--;
day = 31;
}
}
else
{
if(day < 1 && month != 8)
{
month--;
day = 30;
}
else if(month == 8 && day < 1)
{
month--;
day = 31;
}
}
}
if(month < 1)
{
year--;
month = 12;
day = 31;
}
if(month == 2 && day < 1)
{
month--;
day = 31;
}
printf("\n\n\n");
printf("%d - %d - %d ", year, month, day);
printf("\n\n");
panduan(year, month, day);
}
else if(*ch == 0x4b) //判断是否按下左键;
{
if(month == 1)
{
year--;
month = 12;
}
else
{
month--;
}
printf("\n\n\n");
printf("%d - %d - %d ", year, month, day);
printf("\n\n");
panduan(year, month, day);
}
else if(*ch == 0x4d) //判断是否按下右键;
{
if(month == 12)
{
year++;
month = 1;
}
else
{
month++;
}
printf("\n\n\n");
printf("%d - %d - %d ", year, month, day);
printf("\n\n");
panduan(year, month, day);
}
else if(*ch == 0x48) //判断是否按下上键;
{
if(year == 1901)
{
printf("\n对不起,本软件功能有限!请重新输入!!\n");
continue;
}
else
{
year--;
}
printf("\n\n\n");
printf("%d - %d - %d ", year, month, day);
printf("\n\n");
panduan(year, month, day);
}
else if(*ch == 0x50) //判断是否按下下键;
{
year++;
printf("\n\n\n");
printf("%d - %d - %d ", year, month, day);
printf("\n\n");
panduan(year, month, day);
}
else if(*(ch + 1) == 'y')
{
goto s;
}
else
{
break;
}
} while(1);
}
哎,好累啊!!!
|
|