洛谷-P5710 【深基3.例2】數的性質
題目描述
一些數字可能擁有以下的性質:
- 性質 1:是偶數;
- 性質 2:大於 4 且不大於 12。
小A 喜歡這兩個性質同時成立的數字;Uim 喜歡這至少符合其中一種性質的數字;八尾勇喜歡剛好有符合其中一個性質的數字;正妹喜歡不符合這兩個性質的數字。
輸入格式
輸入一個數字 \(x(0\le x \le 1000)\)
輸出格式
輸出這 4 個人是否喜歡這個數字,如果喜歡則輸出1
,否則輸出0
,用空格分隔。
輸入輸出樣例
輸入 #1
12
輸出 #1
1 1 0 0
C++代碼
#include <iostream>
using namespace std;
int main() {
int x;
cin >> x;
bool isEven = (x % 2 == 0);
bool inScope = (x > 4 && x <= 12);
if (isEven && inScope)
cout << 1 << ' ';
else
cout << 0 << ' ';
if (isEven || inScope)
cout << 1 << ' ';
else
cout << 0 << ' ';
if (isEven && !inScope || !isEven && inScope)
cout << 1 << ' ';
else
cout << 0 << ' ';
if (!isEven && !inScope)
cout<< 1 << endl;
else
cout<< 0 <<endl;
return 0;
}