http://oj55.bianchengla.com/problem/623/

  好久没写过题解了,昨天做了一道挺恶心的题目,贴一下代码上来。看了一下提交状况,好像我的代码挺短的了,至少我找不到比我短的代码。RE1,AC。

代码如下:

 #include <cctype>
#include <cstdio>
#include <cstring>
#include <map>
#include <string>
#include <iostream>
#include <algorithm> using namespace std; const int N = ;
char buf[N], *p[];
typedef long long LL;
typedef map<string, LL> MSL;
#define x first
#define y second string get_s(int x) {
string ret = "";
ret += *(p[x]++);
while (islower(*p[x])) ret += *p[x], p[x]++;
return ret;
} int get_d(int x) {
int ret = ;
while (isdigit(*p[x])) ret = ret * + *p[x] - '', p[x]++;
return ret;
} MSL merge(MSL a, MSL b) {
MSL c;
for (MSL::iterator mi = a.begin(); mi != a.end(); mi++) c[mi->x] += mi->y;
for (MSL::iterator mi = b.begin(); mi != b.end(); mi++) c[mi->x] += mi->y;
return c;
} void print(MSL &a) { for (MSL::iterator mi = a.begin(); mi != a.end(); mi++) cout << mi->x << '~' << mi->y << ' '; cout << endl; }
void multiply(MSL &a, LL p) { for (MSL::iterator mi = a.begin(); mi != a.end(); mi++) mi->y *= p; } MSL dfs(int x, char end) {
MSL cur;
//cout << x << ' ' << p[x] << endl;
while (*p[x] && *p[x] != end && *p[x] != ')') {
//cout << x << ' ' << *p[x] << endl;
if (*p[x] == '+') { p[x]++; continue; }
if (isdigit(*p[x])) {
int t = get_d(x);
MSL tmp = dfs(x, '+');
multiply(tmp, t);
cur = merge(cur, tmp);
} else {
if (*p[x] == '(') {
p[x]++; MSL tmp = dfs(x, ')');
if (*p[x] == ')') p[x]++;
if (isdigit(*p[x])) multiply(tmp, get_d(x));
cur = merge(cur, tmp);
} else {
string s = get_s(x);
if (isdigit(*p[x])) cur[s] += get_d(x);
else cur[s]++;
}
}
}
return cur;
} int main() {
//freopen("in", "r", stdin);
while (~scanf("%s", buf)) {
p[] = p[] = buf;
while (*p[] != '=') p[]++; *(p[]++) = ;
MSL ans1, ans2, tmp;
while () {
tmp = dfs(, '+');
ans1 = merge(ans1, tmp);
if (*p[] == ) break;
p[]++;
//cout << p[0] << endl;
}
while () {
tmp = dfs(, '+');
ans2 = merge(ans2, tmp);
if (*p[] == ) break;
p[]++;
//cout << p[1] << endl;
}
MSL::iterator m1 = ans1.begin(), m2 = ans2.begin();
//print(ans1); print(ans2);
while () {
if (m1 == ans1.end()) break;
if (m2 == ans2.end()) break;
if (*m1 != *m2) break;
m1++, m2++;
}
m1 == ans1.end() && m2 == ans2.end() ? puts("YES") : puts("NO");
}
return ;
}

——written by Lyon

最新文章

  1. python下如何安装biopython
  2. win10系统下点击关机却自动重启的问题解决思路
  3. 关于浏览器URL中出现会话验证字符说明
  4. BZOJ1012——[JSOI2008]最大数maxnumber
  5. jquery 判断手势滑动方向(上下左右)
  6. Android:改变Activity切换方式(转载)
  7. python中字符串\r的奇怪问题
  8. jQuery EasyUI动态添加控件或者ajax加载页面后不能自动渲染问题的解决方法
  9. 框架搭建资源 (二) 添加M(模型)
  10. Swiper.js使用方法
  11. 【原创】Linux基础之vi
  12. linux下ping命令出现ping: sendto: Network is unreachable
  13. 正确理解python中的赋值语句:a, b = b, a + b
  14. PriorityBlockingQueue 原理分析
  15. Java笔记Spring(三)
  16. Liferay7 BPM门户开发之12:acitiviti和liferay用户权限体系集成
  17. DL中epoch、batch等的意义【转载】
  18. 你写的什么垃圾代码让Vsync命令不能及时处理呢?(2)
  19. 面试总结之MISC(操作系统,网络,数学,软件开发,测试,工具,系统设计,算法)
  20. C++实现线程同步的几种方式

热门文章

  1. Oracle中函数如何返回结果集
  2. WPF:数据绑定--PropertyChangeNotification属性更改通知
  3. yield和return
  4. go语言:类型转换
  5. Leetcode33.Search in Rotated Sorted Array搜索旋转排序数组
  6. [C#] 利用方向鍵移動 TextBox Focus
  7. 数据库Mysql监控及优化
  8. phpExcel 操作示例
  9. vscode中编译输出c++是乱码
  10. 自定义View系列教程01--常用工具介绍