- UID
- 2198
注册时间2005-6-29
阅读权限255
最后登录1970-1-1
副坛主
该用户从未签到
|
发表于 2009-7-28 22:54:26
|
显示全部楼层
顶个
心情指数~~
#include <stdio.h>
int months[2][13] = {{0,31,28,31,30,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31}} ;
typedef struct Date
{
int year;
int month;
int day;
}Day;
int RunNian(int year)
{
if((!(year%4) && year%100) || !(year%400))return 1;
else return 0;
}
int JianCe(Day * date)
{
int rn=0;
if(date->year<=0 || date->year>9999)return 0;
if( RunNian(date->year) ) rn=1;
if(date->month<=0 || date->month>12)return 0;
if(date->day<=0 || date->day>months[rn][date->month]) return 0;
return 1;
}
Day * ShuRu(int i)
{
Day * d;
d=(Day *)malloc(sizeof(Day));
if(!d)return 0;
if(i==0)printf("请输入您的生日:");
else printf("请输入今天日期:");
scanf("%d-%d-%d",&d->year,&d->month,&d->day);
return d;
}
void ShuChu(Day * date)
{
printf("%4d-%02d-%02d\r\n",date->year,date->month,date->day);
}
int Total(Day ** date)
{
int i,rn,year,month,day,total=0;
for(year=date[0]->year+1;year<date[1]->year;year++)
{
if(RunNian(year))total+=366;
else total+=365; // 也可以建立一个数组
}
if(RunNian(date[0]->year))rn=1;
else rn=0;
for(month=date[0]->month;month<=12;month++)
total+=months[rn][month];
total-=date[0]->day;
if(RunNian(date[1]->year))rn=1;
else rn=0;
for(month=1;month<date[1]->month;month++)
total+=months[rn][month];
total+=date[1]->day;
return total;
}
int main()
{
int year,month,day;
Day * date[2];
int i,t,total;
char * str[]={"体力状态:","情绪状态:","智力状态:"};
char * zt[]={"高潮期","低潮期"};
int zb[]={11,14,16};
int zd[]={23,28,33};
printf("格式为:年-月-日\r\n");
for(i=0;i<2;i++)
{
do
{
t=0;
date[i]=ShuRu(i);
if(!date[i])return 0;
if(!JianCe(date[i])){t=1;printf("输入不合法,请重新输入!\r\n");}
}
while(t);
}
for(i=0;i<2;i++)
{
ShuChu(date[i]);
}
printf("总时间为: %d\r\n",total=Total(date));
for(i=0;i<3;i++)
{
t=total%zd[i];
if(t>zb[i])printf("%s %s\r\n",str[i],zt[0]);
else printf("%s %s\r\n",str[i],zt[1]);
}
return 0;
} |
|