Tsinsen A1112 代数表达式
来源:互联网 发布:linux 多国 语言 查看 编辑:程序博客网 时间:2024/05/20 12:49
http://www.tsinsen.com/A1112
分析:这题有水..随便乱糊弄就过了。较真的话“a+;”应该输出ERROR 3的,随便输出“OK”也过了。不过输出”ERROR 3”也过了,总的来说这题有水。
代码:
#include "bits/stdc++.h"using namespace std;char s[55];int idx, size, Succ, L;int GetOption();int GetVal() { while (s[idx] == '(' && idx < size) ++idx; if (idx >= size) return 0; if (s[idx] == 'a' || s[idx] == 'b' || s[idx] == 'c') { idx = idx + 1; while (s[idx] == '(' && idx < size) ++idx; if (idx >= size) return 1; else return GetOption(); } if (s[idx] == '+' || s[idx] == '-' || s[idx] == '*' || s[idx] == '/') { puts("ERROR 3"); Succ = 0; return 0; } puts("ERROR 1"); Succ = 0; return 0;}int GetOption() { while (s[idx] == '(' && idx < size) ++idx; if (idx >= size) return 0; if (s[idx] == '+' || s[idx] == '-' || s[idx] == '*' || s[idx] == '/') { idx = idx + 1; return GetVal(); } if (s[idx] == 'a' || s[idx] == 'b' || s[idx] == 'c') { puts("ERROR 3"); Succ = 0; return 0; } puts("ERROR 1"); Succ = 0; return 0;}int main() { scanf("%s", s); size = strlen(s); s[--size] = '\0'; Succ = 1; for (int i = 0; i < size; ++i) { if (s[i] == '(') ++L; if (s[i] == ')') { Succ &= (L-- > 0); s[i] = '('; } } if (L != 0 || !Succ) puts("ERROR 2"); else if (GetVal()) puts("OK"); else if (Succ) puts("ERROR 3"); return 0;}
1 0
- Tsinsen A1112 代数表达式
- maxima 代数表达式变换
- 关系代数表达式总结
- 数据库关系代数表达式
- 数据库关系代数表达式学习
- 关系代数表达式的优化
- 数据库关系代数表达式学习
- noip1997 代数表达式 (模拟)
- 数据库关系代数表达式学习
- 二叉树代数求解表达式
- 数据库关系代数表达式学习
- 数据库关系代数表达式学习
- 数据库关系代数表达式学习
- A1112. Stucked Keyboard (20)
- 递归在代数表达式中的运用
- !用二叉树来表示代数表达式
- 用二叉树求解代数表达式
- 用二叉树求解代数表达式
- JavaScript的函数
- 在windows下使用postgreSQL导入tpch的数据表
- cmake链接MySQL分析
- oj问题一-结构体---学生信息排序
- Html快速解析工具——Jsoup使用
- Tsinsen A1112 代数表达式
- 位操作--- Flip Bits
- Linux内核分析——进程的描述和创建
- LintCode_366_斐波纳契数列
- 腾讯测试1
- python文件拷贝工具shutil介绍
- 反转句子中的单词 算法
- 逻辑运算:按位与运算符
- 设计模式3#工厂