#include <iostream>
using namespace std;
int year(int,int,int);
int main()
{
int y,m,t,i;
cout<<"请输入年月日:";
cin>>y>>m>>t;
i=year(y,m,t);
if(i==1)
cout<<"形式合法"<<endl;
else
cout<<"形式不合法"<<endl;
return 0;
}
int year(int a,int b,int c)
{
if((a%4==0&&a%100!=0)||(a%400!=0))
{ if(b==2)
{ if(c>0&&c<=29)
return 1;
else
return 0;
}
else if(b==1||b==3||b==5||b==7||b==8||b==10||b==12)
{ if(c>0&&c<=31)
return 1;
else
return 0;
}
else if(b==4||b==6||b==9||b==11)
{ if(c>0&&c<=30)
return 1;
else
return 0;
}
}
else
{
if(b==1||b==3||b==5||b==7||b==8||b==10||b==12)
{ if(c>0&&c<=31)
return 1;
else
return 0;
}
else if(b==4||b==6||b==9||b==11)
{ if(c>0&&c<=30)
return 1;
else
return 0;
}
else if(b==2)
{
if(c>0&&c<=28)
return 1;
else
return 0;
}
else
return 0;
}
}
虽然开始错了,但还是解决了
最新推荐文章于 2024-11-24 15:24:07 发布
本文提供了一个用于验证输入年月日格式合法性的C++函数,通过判断输入是否符合标准日期格式来确保数据的有效性。
.编写一个函数判断输入的年月日是否合法。输入例如 2012 2 12形式
16万+

被折叠的 条评论
为什么被折叠?



