65,210
社区成员
发帖
与我相关
我的任务
分享#include "stdafx.h"
#include <stdio.h>
#include <string>
using namespace std;
bool IsValidDate(string sDate)
{
int yy;
int mm;
int dd;
yy = atoi(sDate.substr(0,4).c_str());
mm = atoi(sDate.substr(4,2).c_str());
dd = atoi(sDate.substr(6,2).c_str());
if (mm>=1 && mm <=12 && dd <=31 && dd >= 1)
{
if (yy%1000 ==0 && yy%400==0 && mm==2 && dd<=29)
return true;
else if (mm ==1 && mm == 3 && mm ==5 && mm==7 && mm==8 && mm==10 && mm==12 && dd==31)
return true;
else if (mm ==4 && mm == 6 && mm ==9 && mm==11 && dd<=30)
return true;
else if (mm ==2 && dd<=28)
return true;
else return false;
}
return false;
}
int main(int argc, char* argv[])
{
string sDate;
sDate = "20090227";
if (!IsValidDate(sDate))
printf("It is not a Valid Date!\n");
else
printf("It is a Valid Date!\n");
getchar();
return 0;
}#include "stdafx.h"
#include <stdio.h>
#include <string>
using namespace std;
bool IsValidDate(string sDate)
{
int yy;
int mm;
int dd;
yy = atoi(sDate.substr(1,4).c_str());
mm = atoi(sDate.substr(5,6).c_str());
dd = atoi(sDate.substr(7,8).c_str());
if (mm <=12 && dd <=31)
{
if (yy%1000 ==0 && yy%400==0 && mm==2 && dd==29) return true;
else if (mm ==1 && mm == 3 && mm ==5 && mm==7 && mm==8 && mm==10 && mm==12 && dd==31) return true;
else return false;
}
return false;
}
int main(int argc, char* argv[])
{
string sDate;
sDate = "20090229";
if (!IsValidDate(sDate))
printf("It is not a Valid Date!\n");
else
printf("It is a Valid Date!\n");
getchar();
return 0;
}
bool panduan (int a,int b,int c)
{
if (b<=12&&c<=31)
{ if (a%1000==0&&a%400==0&&b=2&&c==29) return true;
else if ((b==1||b==3||b==5||b==7||b==8||b==10||b==12)&&c==31) return true;
else return false;
}
else return false;
}
/*在调用我这个函数的时候,应该这样调用:
bool d;
int x,y,z;
bool panduan (int,int,int);
cin>>x>>y>>z;
d=panduan (x,y,z);
if (d==true) cout<<"有效!\n";
else cout<<"无效!\n";
*/
//(别忘了加上:#include <iostream>)