#42027: cpp解


dvbdarcyvolleyball@gmail.com (no love)

學校 : 新北市私立南山高級中學
編號 : 266888
來源 : [123.252.121.18]
最後登入時間 :
2024-11-21 18:49:47
c461. apcs 邏輯運算子 (Logic Operators) -- apcs | From: [114.136.202.5] | 發表日期 : 2024-09-21 14:20

 借放程式碼,if,else寫爆

#include<iostream>
using namespace std;

int main(){
  int a, b, c;
  int A = 0, B = 0, C = 0, D = 0;
  cin >> a >> b >> c;
  if(a != 0 && b != 0){
    A = 1;
  }
  if(a != 0 || b != 0){
    B = 1;
  }
  if(a == 0 && b != 0 || b == 0 && a != 0){
    C = 1;
  }
  if(A != c && B != c && C != c){
    D = 1;
  }
  if(D == 0){
    if(c == 0){
      if(A == c) cout << "AND" << "\n";
      if(B == c) cout << "OR" << "\n";
      if(C == c) cout << "XOR";
    }
    else{
      if(A == c) cout << "AND" << "\n";
      if(B == c) cout << "OR" << "\n";
      if(C == c) cout << "XOR";
    }
  }
  else{
    cout << "IMPOSSIBLE";
  }
}

 
ZeroJudge Forum