   
- 帖子
- 416
- 积分
- 1324
- 威望
- 1596
- 金钱
- 656
- 在线时间
- 139 小时
          
|
现在又开始学习了,我从一名老师沦落为一名学生了,比过说实话,我还是挺喜欢做学生的,现在初学C语言,NND,一个破题目,想了我一下午,改了又改,改完了又编,编完了又改,哎哟,我发现我的逻辑思维能力真的不是很高,下面我把其中一道挡了我半天的题目发出来大家看看!由于我是初学,所以觉得,真的是想死我了!
. ^6 v* G ?, m \, b* \
2 ~) {$ M! G/ Z$ p5 E% p6 p5 T题目:; `7 w ~6 n2 w f
5 }0 C% c D! b ^$ C
编写一个程序,要求计算出生日到计算日的总天数
9 V' P O; }; H9 l- Y算法:
/ j' D/ K& W! H: D- n1)输入出生年year1、月month1、日date1和计算日年year2、月month2、日date2。& `& }2 j# d' L a
2)统计year1到year2-1的总天数;; j3 w7 L! Y: [2 s$ F, Y. B
3)计算出出生日和计算日是当年的第days1和days2。 # {# D! Y$ A* X7 [
4)总天数等于days+days2-days18 w9 r: K; I7 }! n) J Y' n
根据结果,判断体力、情绪和智力状态
$ X3 u! h1 H" Y- O7 W 方法如下:
% b9 B9 ~$ L% y1 i6 w7 O 体力状态:用总天数除以23,余数在0~11为体力高潮期,否则为体力低潮期。0 w4 b0 |- P9 H
情绪状态:用总天数除以28,余数在0~14为情绪高潮期,否则为情绪低潮期。. y( r# P. t1 n+ j f6 O
智力状态:用总天数除以33,余数在0~16为智力高潮期,否则为智力低潮期。
* t+ E2 v5 a8 F, k6 B! S
7 s _! G0 [6 T我自己写出来的,哇靠真是想死我了!~~~~~NND,死了我成千上万的脑细胞!
' a, K6 D. P/ a: f7 l, b0 A- #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");
- }
- }
复制代码 |
|