c语言高手过来帮帮忙啊!!!!多给分啊~

2024-12-23 08:16:09
推荐回答(5个)
回答1:

这个程序是谁写的啊,一点都不规范,而且还不完整,
把main函数里的switch语句后加个(c)就可以正常编译运行了。
程序的作用是选择要转换为阴历还是阳历,例如选择阴历好后输入一组年月日(格式例1981.11.30,在1980到2015年之间),之后程序将为你转换为阴历(1981.11.5)

帮你注释了两个函数,另外两个函数的思想相同,
总的来说这个程序的逻辑不是很好,不用心看的话很难理解作者的想法,我没时间,要不帮你重新写了,

如果还是看不懂你再留言。

#include
#include
struct data
{
int year1;
int specialmonth;
int month1[13];
};

struct day
{
int year2;
int month2;
int day2;
};

int dis_day1(struct day *op,int *p) /*计算并返回当年距1980年的天数*/
{
int n=0,x;
n+=(op->year2-1980)*365;
for(x=1980;xyear2;x++) /*如果当年是闰年,天数加1*/
if((x%4==0&&x%100!=0)||(x%100==0&&x%400==0))
n+=1;
for(x=1;x<(op->month2);x++)
n+=*(p+x-1);
x=op->year2;
if(((x%4==0&&x%100!=0)||(x%100==0&&x%400==0))&&op->month2>2) /*闰年月份大于2月才多1天*/
n+=1;
n+=(op->day2-1); /*小于2月的话,就算当年是闰年,也要减1天*/
return n;
}

int dis_day2(struct day *op,struct data *p)
{
int n=0,maxmonth,i,x;
for(x=1980;xyear2;x++)
{
if((p+x-1979)->specialmonth==0)
maxmonth=12;
else maxmonth=13;
for(i=0;i if((p+x-1979)->month1[i]==0)
n+=29;
else n+=30;
}
if((p+op->year2-1979)->specialmonth!=0)
if((p+op->year2-1979)->specialmonthmonth2)
op->month2++;
for(i=1;imonth2;i++)
{
if((p+op->year2-1979)->month1[i-1]==0)
n+=29;
else n+=30;
}
n+=(op->day2-1);
n+=46;
return n;
}

/*阳转阴;这里比较复杂,作者的算法大概是:利用前面算出来的天数,直接在自己定义的阴历表里面*/
/*以1979.11.14为起点去代换,*/
void work_out2(struct day *re,struct data *p,int n)
{
int n1=0,maxday,maxmonth,month,day,judge=0;
re->year2=1979;re->month2=11;re->day2=14; /*这里的1979.11.14是1980.1.1的阴历*/
while(1)
{
if(judge==1)
break;
if(p->specialmonth==0)
maxmonth=12;
else
maxmonth=13; /*有闰月的年份多1个月*/
/*下面的if语句是判断当年还剩几个月(maxmonth-month),如果是79年的话,因为是从*/
/*11.14开始,因此只剩1个月(maxmonth-month=1)。 */
if(p->year1==1979)
month=12;
/*其他年份将有(maxmonth-month)12到13个月,至于能否全用到就要看前面算出来的天数n了*/
else
month=1;
for(;month<=maxmonth;month++)
{
if(p->month1[month-1]==0) /*判断当月是大月还是小月*/
maxday=29;
else maxday=30;
if((p->year1==1979)&&(maxday==30)) /*79年的11月是大月,当月日期计数从14号开始*/
day=14;
else day=1; /*其他年份的当月计数从1号开始*/
for(;day<=maxday;day++)
{
if(n1==n)
{
if(maxmonth==13&&month>p->specialmonth)
month-=1;
re->year2=p->year1;
re->month2=month;
re->day2=day;
judge=1;
break;
}
else n1+=1;
}
if(judge==1)break;
}
p++;
}
}

void work_out1(struct day *re,int n,int *p)
{
int year=1980,n1=0,month,day,maxday,judge=0;
re->year2=1980;re->month2=1;re->day2=1;
while(1)
{
*(p+1)=28;
if(judge==1)
break;
if((year%4==0&&year%100!=0)||(year%100==0&&year%400==0))
*(p+1)=29;
for(month=1;month<=12;month++)
{
maxday=*(p+month-1);
for(day=1;day<=maxday;day++)
{
if(n1==n)
{
re->year2=year;
re->month2=month;
re->day2=day;
judge=1;
break;
}
else n1++;
}
if(judge==1)
break;
}
year++;
}
}

main()
{
int n,c;
int sun[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int *p1=sun;
struct day ob,re;
struct data *p2;
/*下面是1979年到2015年的农历表,第1个数字代表年份;第2个数字代表当年的闰月是几月 */
struct data year[37]={
{1979,6, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0 },
{1980,0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0 },
{1981,0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0 },
{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 1, 0 },
{2004,2, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1 },
{2005,0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0 },
{2006,7, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1 },
{2007,0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0 },
{2008,0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0 },
{2009,5, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 },
{2010,0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0 },
{2011,0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0 },
{2012,4, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
{2013,0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
{2014,9, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1 },
{2015,0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0 }
};
p2=year;
printf(" WARNING \n");
printf(" you should take care of it :\n");
printf(" the limted range:\n");
printf(" lunar calendar: 1980.1.1----2015.11.12\n"); /*阳历*/
printf(" soalr calendar: 1980.1.1-----2015.12.31\n"); /*阴历*/

while(1)
{
printf(" please choose one way a/b?\n");
printf(" a: soalr calendar---->lunar calendar\n");
printf(" b: lunar calendar---->soalr calendar\n");
do /*选择除a,b键之外的其他键无效*/
{
c=getchar();
}while(c!='a'&&c!='b');
do
{
printf("your must pay attention to the form\n");
printf("pleae input your date:\n");
scanf("%d.%d.%d",&ob.year2,&ob.month2,&ob.day2); /*输入年、月、日*/
}while(ob.year2<1980||ob.year2>=2016||ob.month2<1||ob.month2>12||ob.day2<1||ob.day2>31);
switch(c)
{
case 'a': /*阳转阴*/
n=dis_day1(&ob, p1);
printf("%d\n",n);
work_out2(&re,p2,n);
printf(" the result is %d.%d.%d\n",re.year2,re.month2,re.day2);
break;
case 'b': /*阴转阳*/
n=dis_day2(&ob,p2);
printf("%d\n",n);
work_out1(&re,n,p1);
printf(" the result is %d.%d.%d\n",re.year2,re.month2,re.day2);
if(ob.month2==(p2+ob.year2-1979)->specialmonth)
{
if((ob.day2!=30)||((p2+ob.year2-1979)->month1[ob.month2]==1))
{
n+=((p2+ob.year2-1979)->month1[ob.month2-1]+29);
work_out1(&re,n,p1);
printf("there is a other result\n:\t%d.%d.%d\n",re.year2,re.month2,re.day2);
}
}
break;
defluat: break;
}
printf("if you want to try again,y/n?\n");
do
{
c=bioskey(0);
}while(c!=0x316e&&c!=0x1579);
if(c==0x316e)
break;
}
}

回答2:

没时间 和我工作时一样 检测的都是超级长的程序 那时俺检测了一个JAVA的程序 是 10W条语句 妈啊 没累死

回答3:

我是楼主!上面的程序不全!这个是接着的!因为打不完了

struct day ob,re; struct data *p2;
struct data year[37]={
{1979,6, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0 },
{1980,0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0 },
{1981,0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0 },
{1982,4, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1 },
{1983,0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0 },
{1984,10,1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1 },
{1985,0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 },
{1986,0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0 },
{1987,6, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0 },
{1988,0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0 },
{1989,0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0 },
{1990,5, 0, 1, 0, 0, 1, 0, 0, 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 0, 1, 0, 1, 0, 1, 0, 1, 0 },
{2013,0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
{2014,9, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1 },
{2015,0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0 }
};
p2=year;
printf(" WARNING \n");
printf(" you should take care of it :\n");
printf(" the limted range:\n");
printf(" lunar calendar: 1980.1.1----2015.11.12\n");
printf(" soalr calendar: 1980.1.1-----2015.12.31\n");

while(1)
{ printf(" please choose one way a/b?\n");
printf(" a: soalr calendar---->lunar calendar\n");
printf(" b: lunar calendar---->soalr calendar\n");
do{c=getchar();}while(c!='a'&&c!='b');
do{
printf("your must pay attention to the form\n");
printf("pleae input your date:\n");
scanf("%d.%d.%d",&ob.year2,&ob.month2,&ob.day2);
}while(ob.year2<1980||ob.year2>=2016||ob.month2<1||
ob.month2>12||ob.day2<1||ob.day2>31);
switch©
{
case 'a':

n=dis_day1(&ob, p1);printf("%d\n",n);
work_out2(&re,p2,n);
printf(" the result is %d.%d.%d\n",re.year2,re.month2,re.day2);break;
case 'b':

n=dis_day2(&ob,p2);printf("%d\n",n);
work_out1(&re,n,p1);
printf(" the result is %d.%d.%d\n",re.year2,re.month2,re.day2);
if(ob.month2==(p2+ob.year2-1979)->specialmonth)
{ if((ob.day2!=30)||((p2+ob.year2-1979)->month1[ob.month2]==1))
{ n+=((p2+ob.year2-1979)->month1[ob.month2-1]+29);
work_out1(&re,n,p1);
printf("there is a other result\n:\t%d.%d.%d\n",re.year2,re.month2,re.day2);
}
}

break;
defluat: break;
}
printf("if you want to try again,y/n?\n");
do{c=bioskey(0);}while(c!=0x316e&&c!=0x1579);if(c==0x316e)break;
}
}

回答4:

最后的main少了一个}

回答5:

哇,直接要人命呀,这么长,看不懂!!!!!!!!!!!!!!!1