...知道自己出生后第一万天纪念日的日期(出生日算第0天)。
发布网友
发布时间:2024-08-27 09:35
我来回答
共5个回答
热心网友
时间:2024-09-07 04:57
main()
{int y,m,d,x,a,b,c
/*Y,M,D为年月日,X为X天纪念日(如10000天纪念日就在输入Y,M,D后输入,10000)a,b,c为内用变量*/
scanf("%d,%d,%d,%d"&y,&m,&d,&x);
a=x/365;
b=(x%365)/30;
c=((x%365)%30);
d=d+c;
if(d>30)
{d=d%30;m=m+d/30;}
m=m+b;
if(m>12)
{m=m%12;y=y+m/12;}
y=y+a;
printf("%d-%d-%d,"y,m,d);
}
输入格式为
y,m,d,x
我好长时间不用C了,语法上可能有点错误,但逻辑应该是对的 ~ (没计算平年与2月和一个月31天的天数差,可能有误差)自己再改改吧 `~
热心网友
时间:2024-09-07 05:00
1974-06-09
热心网友
时间:2024-09-07 05:01
#include <bits/stdc++.h>
using namespace std;
int leap_year(int a)
{
if(a%100!=0&&a%4==0||a%400==0)
{
return 1;
}
else
{
return 0;
}
}
int main()
{
int a,b,c;
int m[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31};
cin>>a>>b>>c;
for(int i=1; i<=10000; i++)
{
if(leap_year(a)==1)
{
m[2]=29;
}
else
{
m[2]=28;
}
if(c>m[b])
{
c=1;
b++;
}
if(b>12)
{
b=1;
a++;
}
c++;
}
cout<<a<<" "<<b<<" "<<c<<endl;
return 0;
}
c++
热心网友
时间:2024-09-07 05:04
输入格式:
从文件的第一行分别读入YY,MM,DD其中1949<=YY<=2002,日期绝对合法。
热心网友
时间:2024-09-07 04:57
#include "stdio.h"
int leap(int &year)
{
return(year%4==0&&year%100!=0||year%400==0);
}
void put(int &year,int &month,int &day)
{
if(leap(year))
{
if(month==2&&day==29)
{
month=month+1;
day=1;
}
else if((month==3&&day==31)||(month==5&&day==31)||(month==7&&day==31)||(month==8&&day==31)||(month==10&&day==31)||(month==1&&day==31))
{
month=month+1;
day=1;
}
else if(month==12&&day==31)
{
year=year+1;
month=1;
day=1;
}
else if((month==4&&day==30)||(month==6&&day==30)||(month==9&&day==30)||(month==11&&day==30))
{
month=month+1;
day=1;
}
else
day=day+1;
}
else if(!leap(year))
{
if(month==2&&day==28)
{
month=month+1;
day=1;
}
else if((month==3&&day==31)||(month==5&&day==31)||(month==7&&day==31)||(month==8&&day==31)||(month==10&&day==31)||(month==1&&day==31))
{
month=month+1;
day=1;
}
else if(month==12&&day==31)
{
year=year+1;
month=1;
day=1;
}
else if((month==4&&day==30)||(month==6&&day==30)||(month==9&&day==30)||(month==11&&day==30))
{
month=month+1;
day=1;
}
else
day=day+1;
}
}
void main()
{
int year,month,day;
loop:printf("Input year month and day:\n");
scanf("%d %d %d",&year,&month,&day);
if(year<1949||year>2002)
{
printf("----Error year,Input again...\n");
goto loop;
}
if(month>12||month<1)
{
printf("----Error month,input again...\n");
goto loop;
}
if(day>31||day<1)
{
printf("----Error day,input again...\n");
goto loop;
}
if(month==4||month==6||month==9||month==11)
{
if(day>30)
{
printf("----Error day,input again...\n");
goto loop;
}
}
if(leap(year))
{
if(month==2)
{
if(day>29)
{
printf("----Error day,input again...\n");
goto loop;
}
}
}
if(!leap(year))
{
if(month==2)
{
if(day>28)
{
printf("----Error day,input again...\n");
goto loop;
}
}
}
for(int i=1;i<=10000;i++)
put(year,month,day);
printf("%d %d %d\n",year,month,day);
}