题目不难,但是很考验读题的能力和运用逻辑符号的能力。
代码:
#include<iostream>
using namespace std;
int main(){
int x;
cin>>x;
bool res[4] = {0,0,0,0};
bool a = (x%2 == 0);
bool b = (x>4 && x <= 12);
if(a && b){
res[0] = 1;
}
if(a || b){
res[1] = 1;
}
if((a && !b) || (b && !a)){
res[2] = 1;
}
if(!a && !b){
res[3] = 1;
}
for(int i = 0; i < 4; i++){
cout<<res[i]<<" ";
}
return 0;
}
另一种比较巧妙的写法:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a,k[5],sum;
int main(){
cin>>a;
if(a>4&&a<=12) sum++;
if(a%2==0) sum++;
if(sum==2) k[1]=1;
if(sum==1||sum==2) k[2]=1;
if(sum==1) k[3]=1;
if(sum==0) k[4]=1;
for(int i=1;i<=4;i++){
cout<<k[i]<<" ";
}
return 0;
}
标签:main,洛谷,int,namespace,bool,include,性质
From: https://www.cnblogs.com/satsuki26681534/p/18048061