   
- 帖子
- 416
- 积分
- 1324
- 威望
- 1596
- 金钱
- 656
- 在线时间
- 139 小时
          
|
现在又开始学习了,我从一名老师沦落为一名学生了,比过说实话,我还是挺喜欢做学生的,现在初学C语言,NND,一个破题目,想了我一下午,改了又改,改完了又编,编完了又改,哎哟,我发现我的逻辑思维能力真的不是很高,下面我把其中一道挡了我半天的题目发出来大家看看!由于我是初学,所以觉得,真的是想死我了!& Z, B6 P! ]8 Y4 e! b
. m2 K4 R5 o: B# W" @( W1 l
题目:
- u- i! m, G! N' p3 E8 y- K3 U. m) i' O
编写一个程序,要求计算出生日到计算日的总天数3 |7 x) D* X& {& t8 f5 x6 `" l
算法:
; k( O+ J% M' m- ]! b2 D1 n1)输入出生年year1、月month1、日date1和计算日年year2、月month2、日date2。
4 r' P6 Z! g- v8 |* U2)统计year1到year2-1的总天数;
* {" K3 |! b! \1 E& u: @/ h/ s0 B3)计算出出生日和计算日是当年的第days1和days2。 , _. Z# P* ]5 I
4)总天数等于days+days2-days1
* B O* p* }+ q根据结果,判断体力、情绪和智力状态& n7 l, |* `4 h9 Q" l) V' d" _6 O7 j
方法如下:
0 e" K D4 Z! D: P1 ~' |2 V 体力状态:用总天数除以23,余数在0~11为体力高潮期,否则为体力低潮期。/ D8 ~& g* b7 Q) N1 s4 ~, p
情绪状态:用总天数除以28,余数在0~14为情绪高潮期,否则为情绪低潮期。
! C; ~$ h* v) n% ] 智力状态:用总天数除以33,余数在0~16为智力高潮期,否则为智力低潮期。
* e- V, r* D, P3 b, b( H
/ A) T& R- ]$ ?' Y5 B8 [# \我自己写出来的,哇靠真是想死我了!~~~~~NND,死了我成千上万的脑细胞!; [+ M- t6 x+ _) q- @, K6 N
- #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");
- }
- }
复制代码 |
|