UVALive 6833 (模拟 水~)
来源:互联网 发布:js和ajax点赞功能代码 编辑:程序博客网 时间:2024/06/05 20:49
题意是给定一个表达式,求这个表达式是运用了哪种规则:
M:乘法优先
L:从左往右
U:ML都符合
I:都不符合
简单的模拟.
#include <bits/stdc++.h>using namespace std;#define maxn 111char a[maxn], n;long long num;bool judge1 () { long long ans = a[0]-'0'; for (int i = 1; i < n; i += 2) { if (a[i] == '+') { ans += a[i+1]-'0'; } else ans *= a[i+1]-'0'; } return ans == num;}vector <long long> gg;bool judge2 () { gg.clear (); long long ans = 0; for (int i = 0; i < n; i += 2) { long long cur = a[i]-'0'; if (a[i+1] == '*') { while (a[i+1] == '*') { cur *= (a[i+2]-'0'); i += 2; } } gg.push_back (cur); } for (int i = 0; i < gg.size (); i++) ans += gg[i]; return ans == num;}int main () { //freopen ("in", "r", stdin); while (scanf ("%s", a) == 1) { scanf ("%lld", &num); n = strlen (a); bool ok1 = judge1 (), ok2 = judge2 (); if (ok1 && ok2) { printf ("U\n"); } else if (!ok1 && !ok2) { printf ("I\n"); } else if (ok2) { printf ("M\n"); } else { printf ("L\n"); } } return 0;}
0 0
- UVALive 6833 (模拟 水~)
- UVALive 6833【模拟】
- UVALive 4723 水模拟
- UVALive 6833Miscalculation (模拟)
- UVALive 3497 brainfuck [模拟]
- UVALive 7503--模拟
- UValive 7269 (模拟)
- UVALive 7327【模拟】
- UVALive 7608Robot(模拟)
- UVALive 7752 模拟
- 【模拟】 UVALive 4168 Lampyridae Teleportae
- UvaLive--6664--Clock Hands【模拟】
- UVALive 4887 Soccer 状压+模拟
- UVALive 3971 Assemble(模拟 + 二分)
- UVALive - 6269 Digital Clock 模拟
- UVALive 5873 - Tree Inspections 【模拟】
- uvalive 4254(二分+模拟)
- UVALive 7139 Rotation(模拟)
- no android sdk found
- Floyd、Dijkstra、Bellman-Ford、SPFA的比较
- 电子或通信领域当前的主流技术及其社会需求调查报告
- Python标准库01 正则表达式 (re包)
- mysql-删除/更新相同的记录的前n条
- UVALive 6833 (模拟 水~)
- Python标准库02 时间与日期 (time, datetime包)
- Java 学习历程(二)面向对象编程
- 实时数据库--概念浅述
- ORACLE数据库开发
- Remove Redundant Characters
- Python标准库03 路径与文件 (os.path包, glob包)
- delphi7 下的Excel导出
- iOS 官方文档NSCalendar