【程式解題】APCS 第一題:邏輯運算子 C解法
#include <stdio.h>
#include <stdlib.h>
int main(){
int i,j;
int a,b,r;//input
int t;
scanf("%d%d%d",&a,&b,&r);
if(a>b){//讓 a 一定是小的
t=a;
a=b;
b=t;
}
if(r){
if(a==0&&b!=0) printf("OR\nXOR\n");
else if(a!=0&&b!=0) printf("AND\nOR\n");
else printf("IMPOSSIBLE\n");
}
else {
if(a==0){
if(b){
printf("AND\n");
}else if(b==0){
printf("AND\nOR\nXOR\n");
}
}else if(a!=0&&b!=0){
printf("XOR\n");
}
else printf("IMPOSSIBLE\n");
}
return 0;
}
留言
張貼留言