Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
贴代码#include <stdio.h> #include <string.h> char data[124]; int paras[124]; bool inputData() { scanf("%s", &data); return (strcmp(data, "0") != 0); } bool getValue(int values[]) { int len = strlen(data); int pl = 0; for (int i = len - 1; i >= 0; -- i) { if (data[i] >= 'p' && data[i] <= 't') { paras[pl] = values[data[i] - 'p']; ++ pl; } else if (data[i] == 'K') { paras[pl - 2] = (paras[pl - 2] & paras[pl - 1]); -- pl; } else if (data[i] == 'A') { paras[pl - 2] = (paras[pl - 2] | paras[pl - 1]); -- pl; } else if (data[i] == 'N') { paras[pl - 1] = 1 - paras[pl - 1]; } else if (data[i] == 'C') { paras[pl - 2] = ((paras[pl - 1] ^ 1) | paras[pl - 2]); -- pl; } else if (data[i] == 'E') { paras[pl - 2] = 1 - (paras[pl - 1] ^ paras[pl - 2]); -- pl; } } return (paras[0] == 1); } void process() { bool ret = true; int values[5]; for (int i = 0; i < 32; ++ i) { for (int j = 0; j < 5; ++ j) { values[j] = (i & (1 << j)) ? 1 : 0; } ret &= getValue(values); if (!ret) { break; } } if (ret) { printf("tautology\n"); } else { printf("not\n"); } } int main() { while (inputData()) { process(); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator