dos 万年历
文章转自王牌软件
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
只回答业务咨询
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
/************************************************** 万年历1.1 修正“~~~~”小于-999时不对称的问题 修正 年份可以小于-9999的问题 添加十二生肖 添加干支纪年 2013-05-12-14:22 *************************************************/ #include <stdio.h> #include <string.h> #include <conio.h> #include <windows.h> #include <math.h> #include <time.h> typedef unsigned char u_char; #define YEAR_MAX 9999 int show(int year, int month, int Cnt); int key_Move(int *year, int *month); int nowTime(int *year, int *month); int Animal(int year); int GanZhi(int year); int SetCursorPosition(int x, int y); int SetCursorInfo(int size, int visible ); int SetTitle(char *content); int main(int argc, char *argv[]) { int year = -988; int month= 2; int Cnt = 1; SetCursorInfo(-1, 0); SetCursorPosition(0, 2); printf(" 日 一 二 三 四 五 六\n"); SetTitle("万年历1.1"); nowTime(&year, &month); show(year, month, Cnt); SetCursorPosition(0, 0); Animal(year); putchar(0x20); putchar(0x20); GanZhi(year); while (1) { Cnt = key_Move(&year, &month); show(year, month, Cnt); SetCursorPosition(0, 0); Animal(year); putchar(0x20); putchar(0x20); GanZhi(year); } return 0; } //************************************************* static int show_one(int year, int month) { //参考点:2000年01月01 星期六 int one; int Cnt = 0; int mo = 0; int buff[] = {31,28,31,30,31,30,31, 31,30,31,30,31}; int i; long longN= 0; longN = year - 2000; Cnt = abs(longN / 400); Cnt +=abs(longN / 4); Cnt -=abs(longN / 100); longN *= 365; for (i=0; i<12; i++) { if (i < month-1) { mo += buff[i]; } else break; } if (longN < 0) { longN = longN - Cnt + mo; if (year%100 == 0) { if (year%400 == 0) { //闰年 if (month > 2) longN++; } } else { if (year%4 == 0) { //闰年 if (month > 2) longN++; } } } else { longN = longN + Cnt + mo; if (longN > 60) { //当超过2000年的2月时,加上2000年2月的29号 longN++; } } one = 6; one += (longN % 7); one %= 7; return one; } static int show_mon(int year, int month) { int buff[] = {1, 3, 5, 7, 8, 10, 12}; int mon = 30; int i; for (i=0; i<7; i++) { if (month == buff[i]) { mon++; break; } } if (month == 2) { mon = 28; if (year%100 == 0) { if (year%400 == 0) { //闰年 mon++; } } else { if (year%4 == 0) { //闰年 mon++; } } } return mon; } int show(int year, int month, int Cnt) { int Num = 0; int Mon = 0; int one = 0; int i, j; one = show_one(year, month); Mon = show_mon(year, month); if (year <= 0) { year--; } SetCursorPosition(7, 0); if (year >= -999) printf(" %4d年%02d月\n", year, month); else printf(" %4d年%02d月\n", year, month); // 修正“~~~~”小于-999时不对称的问题 if (Cnt == 1) printf(" ~~~~ \n"); else if (Cnt == 2) printf(" ~~\n"); printf("\n"); for (j=0; j<6; j++) { printf(" "); for (i=0; i<7; i++) { if ( (j*7 + i) >= one ) { Num++; if (Num > Mon) { printf(" "); } else printf("%2d ",Num); } else printf(" "); } puts(""); } return 0 ; } //********************************************************** int key_Move(int *year, int *month) { u_char ch = 0; static int Cnt= 1; lp: ch = getch(); if (ch == 0xe0) { ch = getch(); switch (ch) { case 0x4b: //left Cnt--; if (Cnt < 1) Cnt = 1; break; case 0x4d: //right Cnt++; if (Cnt > 2) Cnt = 2; break; case 0x50: //down if (Cnt == 1) { (*year)++; if (*year > YEAR_MAX) { (*year)= YEAR_MAX; *month = 12; } } else if (Cnt == 2) { (*month)++; if (*month > 12) { (*year)++; *month = 1; } } break; case 0x48: //up if (Cnt == 1) { (*year)--; if (*year < -YEAR_MAX) { (*year)= -YEAR_MAX; *month = 12; } } else if (Cnt == 2) { (*month)--; if (*month < 1) { // 修正 年份可以小于-9999的问题 (*year)--; if (*year < -YEAR_MAX+1) { (*year)= -YEAR_MAX+1; } *month = 12; if ( *year == -YEAR_MAX+1) *month = 1; } } break; default: ; } } else if (ch == 0x1b) { exit(0); } else { goto lp; } return Cnt; } //************************************************** int nowTime(int *year, int *month) { time_t tim = 0; time_t temp= 0; int add = 0; int i = 0; int buff[] = {31,28,31,30,31,30,31, 31,30,31,30,31}; tim = time(NULL); //零时区1970年1月1日0时0分0秒开始 tim += (8*3600); temp = tim % (24*3600); tim /= (24*3600); if (temp > 0) { tim++; } temp = tim%365; //余的天数 if (tim <= 365) { temp = tim; } if (temp == 0) { tim -= 365; temp = 365; } tim = tim / 365; //年数 nowTime_a: add = tim / 4; add += (tim / 400); add -= (tim / 100); if (tim%4 >= 2) { add++; } if (temp-add <= 0) { tim--; temp += 365; goto nowTime_a; } temp -= add; tim += 1970; if ( tim%100 == 0 ) { if (tim%400 == 0) { buff[1]++; } } else { if (tim%4 == 0) { buff[1]++; } } while ( temp > 0 ) { if (i >= 12) break; if (buff[i] > temp) { break; } temp -= buff[i]; i++; } *year = tim; *month= i+1; return temp; } //************************************************ int Animal(int year) { //2013年是蛇年 char buff[][3] = {"蛇", "马", "羊", "猴", "鸡", "狗", "猪", "鼠", "牛", "虎", "兔", "龙"}; int Cnt = 0; Cnt = year - 2013; Cnt %= 12; if ( Cnt < 0 ) { Cnt += 12; } printf("%s", buff[Cnt]); return 0; } int GanZhi(int year ) { int Cnt = 0; char name[][5] = { "甲子", "乙丑", "丙寅", "丁卯", "戊辰", "己巳", "庚午", "辛未", "壬申", "癸酉", "甲戌", "乙亥", "丙子", "丁丑", "戊寅", "己卯", "庚辰", "辛巳", "壬午", "癸未", "甲申", "乙酉", "丙戌", "丁亥", "戊子", "己丑", "庚寅", "辛卯", "壬辰", "癸巳", "甲午", "乙未", "丙申", "丁酉", "戊戌", "己亥", "庚子", "辛丑", "壬寅", "癸卯", "甲辰", "乙巳", "丙午", "丁未", "戊申", "己酉", "庚戌", "辛亥", "壬子", "癸丑", "甲寅", "乙卯", "丙辰", "丁巳", "戊午", "己未", "庚申", "辛酉", "壬戌", "癸亥" }; Cnt = year - 2013 - 30 - 1; Cnt %= 60; if ( Cnt < 0 ) { Cnt += 60; } printf("%s", name[Cnt]); return 0; } //************************************************** int SetCursorPosition(int x, int y) { if (x < 0) x = 0; if (y < 0) y = 0; COORD XY = {x,y}; HANDLE *hd = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(hd, XY); return 0; } int SetCursorInfo(int size, int visible ) { if (size > 100) size = 100; CONSOLE_CURSOR_INFO info; HANDLE *hd = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleCursorInfo(hd,&info); if (size > 0 ) info.dwSize = size; info.bVisible = visible; SetConsoleCursorInfo(hd,&info); return 0; } int SetTitle(char *content) { HANDLE *hd = GetStdHandle(STD_OUTPUT_HANDLE); if (content == NULL) return -1; SetConsoleTitle(content); return 0; } |
学习日记,兼职软件设计,软件修改,毕业设计。
本文出自 学习日记,转载时请注明出处及相应链接。
本文永久链接: https://www.softwareace.cn/?p=435