Description
定义类Integer,包括:
1.一个int类型的属性data。
2. 构造函数。
3. bool judge()方法:求data的各位数字之和,如果这个和是偶数,则返回假,否则返回真。
Input
输入若干个正整数,每个占一行。
Output
每行输入对应一行输出,是对每行输入对应的对象调用judge()方法后输出的结果。
Sample Input
123
456
1
33
Sample Output
NO
YES
YES
NO
#include<bits/stdc++.h>
using namespace std;
int Sum(int n)
{
int sum=0;
for(int i=0;i<8;i++)
{
sum=n%10+sum;
n=n/10;
}
return sum;
}
class Integer
{
private:
int data;
public:
Integer(int d):data(d){}
bool judge()
{
if(Sum(data)%2==0)
return 0;
else return 1;
}
};
int main()
{
int i;
while(cin>>i)
{
Integer INT(i);
if (INT.judge())
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}