高分求两道C语言程序题!!好的话继续追加分数!!

2024-11-08 16:11:25
推荐回答(3个)
回答1:

#include

main()
{
int year, month, day, run, num;
while(scanf("%d%d%d", &year, &month, &day) != EOF)
{
if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
run = 1;
else
run = 0;

if(run == 1)
switch(month)
{
case 1 : num = day;break;
case 2 : num = 31 + day;break;
case 3 : num = 60 + day;break;
case 4 : num = 91 + day;break;
case 5 : num = 121 + day;break;
case 6 : num = 152 + day;break;
case 7 : num = 182 + day;break;
case 8 : num = 213 + day;break;
case 9 : num = 244 + day;break;
case 10 : num = 274 + day;break;
case 11 : num = 305 + day;break;
case 12 : num = 335 + day;break;
}
else
switch(month)
{
case 1 : num = day;break;
case 2 : num = 31 + day;break;
case 3 : num = 59 + day;break;
case 4 : num = 90 + day;break;
case 5 : num = 120 + day;break;
case 6 : num = 151 + day;break;
case 7 : num = 181 + day;break;
case 8 : num = 212 + day;break;
case 9 : num = 243 + day;break;
case 10 : num = 273 + day;break;
case 11 : num = 304 + day;break;
case 12 : num = 334 + day;break;
}

printf("%d\n", num);

}

return 0;
}
这是年月日的
Sample Input
1983 3 17
1984 3 21
2000 2 29

Sample Output
76
81
60

#include
#include
int main()
{
bool f( int num);
long n, i, j;

while(scanf("%ld", &n) != EOF)
{
if(n == 0)
return 0;

for(i = 2; i < n; i++)
{
if(f(i) == 1 && f(n - i) == 1)
{
printf("%ld = %ld + %ld\n", n, i, n - i);
break;
}
}
}

return 0;
}

bool f( int num)
{
if (num==2||num==3||num==5)
return 1;
unsigned long c=7;
if (num%2==0||num%3==0||num%5==0||num==1)
return 0;
int maxc=int(sqrt(num));
while (c<=maxc)
{
if (num%c==0)
return 0;
c+=4;
if (num%c==0)
return 0;
c+=2;
if (num%c==0)
return 0;
c+=4;
if (num%c==0)
return 0;
c+=2;
if (num%c==0)
return 0;
c+=4;
if (num%c==0)
return 0;
c+=6;
if (num%c==0)
return 0;
c+=2;
if (num%c==0)
return 0;
c+=6;
}
return 1;
}

这是整数分解的
Sample Input

8
20
42
0

Sample Output

8 = 3 + 5
20 = 3 + 17
42 = 5 + 37

这2道是ACM上原题,我以前做过的,AC

回答2:

int main()
{
void f(int y, int m, int d);
int year, month, day;
printf("输入年月日:\n");
scanf("%d%d%d", &year, &month, &day);
f(year, month, day);
return 0;
}
void f(int y, int m, int d)
{
int i, sum=0, m1[12]={0};
for(i=1; i {
if(i==2&&y%400==0||y%100!=0&&y%4==0) m1[i]+=29;
else if(i==2) m1[i]+=28;
else if(i==4||i==6||i==9||i==11) m1[i]+=30;
else m1[i]+=31;
}
for(i=1; i sum+=d;
printf("这是这一年的第%d天", sum);
}

回答3:

问~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~伟大的~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~老师