【程式解題】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;

}

留言

這個網誌中的熱門文章

【程式解題】2019年4月TOI練習賽新手組 - 滿意度調查 (Survey of Satisfaction) C解法(註解版)

【程式解題】 ZeroJudge a038數字翻轉 C解法(逐行註解)