09/01/12 02:17:30
>>697 3問目
#include<stdio.h>
#include<stdlib.h>
#define ADJUST(v) (((v)=='1' || (v)=='0')?(v):'X')
int myNOT(int A){
if(A=='1') return '0';
if(A=='0') return '1';
return 'X';
}
int myOR(int A, int B){
if(A=='1' || B=='1') return '1';
if(A=='0' && B=='0') return '0';
return 'X';
}
int myAND(int A, int B){
if(A=='0' || B=='0') return '0';
if(A=='1' && B=='1') return '1';
return 'X';
}
int myNOR(int A, int B){ return myNOT(myOR(A, B)); }
int myNAND(int A, int B){ return myNOT(myAND(A, B)); }
int myXOR(int A, int B){ return myOR(myAND(myNOT(A), B), myAND(A, myNOT(B))); }
int myRSFF(int S, int R, int Q){
return myXOR(myOR(myAND(myNOR(S, R), Q), myAND(myXOR(S, R), S)), myAND(myAND(S, R), 'X'));
}
int main(void){
char buf[3][10];
scanf("%9s%9s%9s", buf[0], buf[1], buf[2]);
printf("S=%c R=%c Q=%c --> Q'=%c\n", buf[0][0], buf[1][0], buf[2][0], myRSFF(buf[0][0], buf[1][0], buf[2][0]));
return 0;
}