1,判断闰年
#include<iostream>
using namespace std;
int main()
{
int year;
cin>>year;
if(year%4==0&&year%100!=0||year%400==0)
cout<<"IsLeapYear"<<endl;
else
cout<<"NotLeapYear"<<endl;
return 0;
}
2,判断数的类型
#include<iostream>
using namespace std;
int main()
{
double i;
cin>>i;
if(i>1e-10)
{
if(int(i)==i)
cout<<"positive integer"<<endl;
else
cout<<"positive real"<<endl;
}
else if(i<-1e-10)
{
if(int(i)==i)
cout<<"negative integer"<<endl;
else
cout<<"negative real"<<endl;
}
else
cout<<"zero"<<endl;
return 0;
}
3,判断数字
#include<iostream>
using namespace std;
int main()
{
char c;
cin>>c;
if(c>='0'&&c<='9')
cout<<1;
else
cout<<0;
return 0;
}
4,判断整数的位数
#include <iostream>
using namespace std;
int main()
{
unsigned int count = 1;
int n;
cin>> n;
for (int i=0;i<n&&n>= 10; ++i)
{
n=n/10;
++ count;
}
cout << count << endl;
return 0;
}
5,判断字符类型
#include<iostream>
using namespace std;
int main()
{
char ch;
ch=cin.get();
if(ch>='A'&&ch<='Z')
cout<<"1"<<endl;
else if(ch>='a'&&ch<='z')
cout<<"2"<<endl;
else if(ch>='0'&&ch<='9')
cout<<"0"<<endl;
else
cout<<"-1"<<endl;
return 0;
}