栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 3025 How can I satisfy th...

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 3025 How can I satisfy th...

#include <cstdio>#include <cstring>using namespace std;char str[110];char sta[110];int top;int stanum[110];int stop;int num[128];int res1[3][3] = { 0, 0, 0, 0, 1, 1, 0, 1, 2.};int res2[3][3] = { 0, 1, 2, 1, 1, 2, 2, 2, 2,};int res[3] = {2, 1, 0};bool solve(int p, int q, int r){ num['P'] = p; num['Q'] = q; num['R'] = r; int len = strlen(str); top = 0; stop = 0; for (int i = 0; i < len; ) { if ((str[i] >= '0' && str[i] <= '9') || (str[i] >= 'A' && str[i] <= 'Z')) { if (str[i] >= '0' && str[i] <= '9') { stanum[stop++] = str[i] - '0'; } else { stanum[stop++] = num[str[i]]; } while (top > 0 && sta[top - 1] == '-') { stanum[stop - 1] = res[stanum[stop - 1]]; top--; } i++; } else { if (str[i] == ')') { char opt = sta[top - 1]; int ans; int b = stanum[--stop]; int a = stanum[--stop]; if (opt == '*') { ans = res1[a][b]; } else { ans = res2[a][b]; } stanum[stop++] = ans; top -= 2; while (top > 0 && sta[top - 1] == '-') { stanum[stop - 1] = res[stanum[stop - 1]]; top--; } } else { sta[top++] = str[i]; } i++; } } return stanum[0] == 2;}int main(){ while (scanf("%s", str) == 1) { if (str[0] == '.') break; int p, q, r; int cc = 0; for (p = 0; p <= 2; p++) { for (q = 0; q <= 2; q++) { for (r = 0; r <= 2; r++) { if (solve(p, q, r)) cc++; } } } printf("%dn", cc); } return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/376561.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号