qq_34015982 于 2016.02.25 09:09 提问

3个回答

caozhy      2016.02.25 21:29
`````` #include <stdio.h>

int mt[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

void set2(int y)
{
if (y % 4 != 0)
{
mt[2] = 28;
}
else
{
if (y % 100 == 0 && y % 400 != 0)
mt[2] = 28;
else
mt[2] = 29;
}
}

{
printf("1. y/n/d -> yd\n");
printf("2. yd -> y/n/d\n");
printf("3. exit\n");
}

int ymd2yd(int y, int m, int d)
{
set2(y);
int r = 0;
for (int i = 0; i < m; i++)
r += mt[i];
r += d;
return r;
}

void yd2ymd(int yd, int * r)
{
set2(r[0]);
int m = 0;
while (yd > mt[m])
{
yd -= mt[m++];
}
r[1] = m;
r[2] = yd;
}

int main()
{
char c;
while (scanf("%c", &c), 1)
{
switch (c)
{
case '1':
int y, int m, int d;
scanf("%d", &y);
scanf("%d", &m);
scanf("%d", &d);
printf("%d\n", ymd2yd(y, m, d));
break;
case '2':
int yd;
int r[3];
scanf("%d", &r[0]);
scanf("%d", &yd);
yd2ymd(yd, r);
printf("%d %d %d\n", r[0], r[1], r[2]);
break;
case '\n':
break;
default:
return 0;
}
}
return 0;
}

``````
caozhy      2016.02.25 21:33
1. y/n/d -> yd
2. yd -> y/n/d
3. exit 1 2016 3 1 61
4. y/n/d -> yd
5. yd -> y/n/d
6. exit 1 2016 7 18 200
7. y/n/d -> yd
8. yd -> y/n/d
9. exit 1 2015 12 31 365
10. y/n/d -> yd
11. yd -> y/n/d
12. exit 2 2016 61 2016 3 1
13. y/n/d -> yd
14. yd -> y/n/d
15. exit 2 2015 61 2015 3 2
16. y/n/d -> yd
17. yd -> y/n/d
18. exit 2 2015 225 2015 8 13
19. y/n/d -> yd
20. yd -> y/n/d
21. exit 3 Press any key to continue
caozhy      2016.02.25 21:33
`````` 1. y/n/d -> yd
2. yd -> y/n/d
3. exit 1
2016 3 1
61
1. y/n/d -> yd
2. yd -> y/n/d
3. exit 1
2016 7 18
200
1. y/n/d -> yd
2. yd -> y/n/d
3. exit 1
2015 12 31
365
1. y/n/d -> yd
2. yd -> y/n/d
3. exit 2
2016 61
2016 3 1
1. y/n/d -> yd
2. yd -> y/n/d
3. exit 2
2015 61
2015 3 2
1. y/n/d -> yd
2. yd -> y/n/d
3. exit 2
2015 225
2015 8 13
1. y/n/d -> yd
2. yd -> y/n/d
3. exit 3
Press any key to continue
``````

#include &amp;lt;stdio.h&amp;gt;int  DayofYear(int year, int month, int day){    int s=0,i,a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; if(year%4==0&amp;amp;&amp;amp;year%100!=0||year%400==0)  a[2]=29; for(i=1;i&amp;lt...

#include int judge_leap(int year) { if (((year % 4 == 0)&(year % 100 != 0)) || (year % 400 == 0)) { return 1; } else { return 0; } } int main() { int y = 0; printf("请输入要判断的年份:"); scanf(

#include <stdio.h> #include <stdtib.h> int good(int a,int b) { if(a>b) return a; else if(a<b) return b; else if(a=b) return a; } int main() { int a,b,c; scan

//用函数编程计算并输出杨辉三角形 #include "stdio.h" int main() { int a[40][40]= {0}; int i,j,k; printf("请输入你想要表示的杨辉三角形的大小k:\n"); scanf("%d",&k); for(i=1; i<=k;i++) { a[i][1]=1;

#include #define MAXS 20 void f( char *p ); void ReadString( char *s ); /* 由裁判实现，略去不表 */ int main() { char s[MAXS]; ReadString(s); f(s); printf("%s\n", s); return 0; } /* 你的代

//反复校验用户输入的日期，直到年、月、日都合法,计算该日在本年中为第几天？（注意考虑闰年问题） //刚刚学习C语言,本人的最优化代码,仅供参考 import int days(int year,int month,int day) {  //定一个函数 返回值为该日在本年中的天数     int Day[12] = {31,28,31,30,31,30,31,31,30