   
- 帖子
- 416
- 积分
- 1324
- 威望
- 1596
- 金钱
- 656
- 在线时间
- 139 小时
          
|
现在又开始学习了,我从一名老师沦落为一名学生了,比过说实话,我还是挺喜欢做学生的,现在初学C语言,NND,一个破题目,想了我一下午,改了又改,改完了又编,编完了又改,哎哟,我发现我的逻辑思维能力真的不是很高,下面我把其中一道挡了我半天的题目发出来大家看看!由于我是初学,所以觉得,真的是想死我了!8 r2 B) W; m. N4 r l; X
+ T; w2 c2 V: y$ U. l题目:
7 y7 w* B* l. E* M- N5 D+ X! N) E7 I- h- A# u; ^& v. [, D$ Q( E4 s
编写一个程序,要求计算出生日到计算日的总天数
; r. B5 E8 g, }& K5 A+ h* {3 T算法:
0 Z" _4 s/ |: |* ^+ F, ~% E% l1 q- d j9 }1)输入出生年year1、月month1、日date1和计算日年year2、月month2、日date2。6 {/ o1 ]+ G& Z0 P
2)统计year1到year2-1的总天数;
. s5 V, d, X0 V& N7 M4 g5 S3)计算出出生日和计算日是当年的第days1和days2。
( y% ?1 b# |0 Q- O7 k: ~4)总天数等于days+days2-days1" u% e( ^% e# T
根据结果,判断体力、情绪和智力状态, Y" d( W- y. b; o& s
方法如下:
) }7 l1 A7 ]- c! ~; Y* U 体力状态:用总天数除以23,余数在0~11为体力高潮期,否则为体力低潮期。- Q& U% {- k% n3 A
情绪状态:用总天数除以28,余数在0~14为情绪高潮期,否则为情绪低潮期。0 s7 F4 W- q& ~9 \% C4 {& i
智力状态:用总天数除以33,余数在0~16为智力高潮期,否则为智力低潮期。
8 z" x( s5 Q% B3 z, }. i1 l+ n2 J" h1 ]& v7 K1 R
我自己写出来的,哇靠真是想死我了!~~~~~NND,死了我成千上万的脑细胞!6 ~0 Q9 p7 w# v! \
- #include <stdio.h>
- int day(int year, int month)
- {
- int days;
- for(int n = 1; n <= month; n++)
- {
- if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
- {
- switch (n)
- {
- case 1:
- days = 31;
- break;
- case 2:
- days += 29;
- break;
- case 3:
- days += 31;
- break;
- case 4:
- days += 30;
- break;
- case 5:
- days += 31;
- break;
- case 6:
- days += 30;
- break;
- case 7:
- days += 31;
- break;
- case 8:
- days += 31;
- break;
- case 9:
- days += 30;
- break;
- case 10:
- days += 31;
- break;
- case 11:
- days += 30;
- break;
- case 12:
- days += 31;
- break;
- default:
- printf("您输入的月份大于12个月,因此不合格!");
- }
- }
- else
- {
- switch (n)
- {
- case 1:
- days = 31;
- break;
- case 2:
- days += 28;
- break;
- case 3:
- days += 31;
- break;
- case 4:
- days += 30;
- break;
- case 5:
- days += 31;
- break;
- case 6:
- days += 30;
- break;
- case 7:
- days += 31;
- break;
- case 8:
- days += 31;
- break;
- case 9:
- days += 30;
- break;
- case 10:
- days += 31;
- break;
- case 11:
- days += 30;
- break;
- case 12:
- days += 31;
- break;
- default:
- printf("您输入的月份大于12个月,因此不合格!");
- }
- }
- }
- return days;
- }
- void main()
- {
- int year1, year2, month1, month2, date1, date2;
- int days1, days2,alldays;
- printf("请按格式输入出生年,月,日:");
- scanf("%d,%d,%d", &year1, &month1, &date1);
- printf("请按格式输入当前年,月,日:");
- scanf("%d,%d,%d", &year2, &month2, &date2);
- days1=day(year1, month1);
- days2=day(year2, month2);
- for(int n=year1, days=0; n < year2; n++)
- {
- if(n % 4 == 0 && n % 100 != 0 || n % 400 == 0)
- {
- days+=366;
- }
- else
- {
- days+=365;
- }
- }
- alldays=days-(days1+date1)+(days2+date2);
- printf("==============================\r\n结果:\r\n==============================\r\n");
- printf("从出生年到现年总共%d天。\r\n", alldays);
- if ( alldays%23>0 && alldays%23<11 )
- {
- printf("您现在处于体力高潮期\r\n");
- }
- else
- {
- printf("您现在处于体力低潮期\r\n");
- }
- if ( alldays%28>0 && alldays%28<14 )
- {
- printf("您现在处于智力高潮期\r\n");
- }
- else
- {
- printf("您现在处于智力低潮期\r\n");
- }
- if ( alldays%33>0 && alldays%33<16 )
- {
- printf("您现在处于情绪高潮期\r\n");
- }
- else
- {
- printf("您现在处于情绪低潮期\r\n");
- }
- }
复制代码 |
|