   
- 帖子
- 416
- 积分
- 1324
- 威望
- 1596
- 金钱
- 656
- 在线时间
- 139 小时
          
|
现在又开始学习了,我从一名老师沦落为一名学生了,比过说实话,我还是挺喜欢做学生的,现在初学C语言,NND,一个破题目,想了我一下午,改了又改,改完了又编,编完了又改,哎哟,我发现我的逻辑思维能力真的不是很高,下面我把其中一道挡了我半天的题目发出来大家看看!由于我是初学,所以觉得,真的是想死我了!
( R# u g. p5 \/ N$ m
* h5 s9 y# Q, d4 p& E* I2 M0 ]/ L题目:
3 h8 z8 [; {1 x, @' w& R
8 a0 T0 `8 B6 J" l4 Z编写一个程序,要求计算出生日到计算日的总天数" y# C' e% t( ?) D5 B" Q
算法:# e$ O/ }* O0 a: l( H
1)输入出生年year1、月month1、日date1和计算日年year2、月month2、日date2。. i* Q2 c& J* P+ Y
2)统计year1到year2-1的总天数;) p, \7 p$ h( ]0 Z
3)计算出出生日和计算日是当年的第days1和days2。 3 E0 [9 Q3 j5 f" U+ l0 H) {( n
4)总天数等于days+days2-days1, y6 z1 L- s6 ~) X# a/ W
根据结果,判断体力、情绪和智力状态4 c# I J( M) ?. a9 M+ y
方法如下:
) U" x/ K4 |; `9 ?# m, E, I 体力状态:用总天数除以23,余数在0~11为体力高潮期,否则为体力低潮期。; A, F7 W3 H; G# d5 p* {. `& Q/ n" {
情绪状态:用总天数除以28,余数在0~14为情绪高潮期,否则为情绪低潮期。
% p, m: J s M3 H1 [8 _- c 智力状态:用总天数除以33,余数在0~16为智力高潮期,否则为智力低潮期。% [0 \. B# i7 w* R+ A9 f$ R
, q& h0 L/ X- Z2 m我自己写出来的,哇靠真是想死我了!~~~~~NND,死了我成千上万的脑细胞!. V4 K& b/ Z, [' u# S# m: _ s+ 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");
- }
- }
复制代码 |
|