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

BUAA 623 Chem is Try!的更多相关文章

  1. Buaa菜鸡从今天好好学打码,好好学数学,好好学英语,好好打篮球,好好锻炼,好好吃饭,好好... 好好找女朋友!

    新链接: https://iamparasite.github.io/

  2. #CSDN刷票门# 有没有人在恶意刷票?CSDN请告诉我!用24小时监控数据说话!

    特别声明: 此次并非针对其他参与2013中国十大优秀开源项目的同行,体系有漏洞要谴责的是制定规则并从中获益但不作为的权贵,草根们制定不了规则但可发现和利用漏洞,这是程序员应有反叛精神没错.但被作为道具 ...

  3. BUAA & ICT 夏令营之旅

    我还只有二十几岁,总应该相信点什么吧. ================================ 7.10午后坐火车赶到北京.一路上火车行驶在茫茫云海里.车窗外的世界是这样子的:一片广袤的原野 ...

  4. 開賣!下集 -- ASP.NET 4.5 專題實務(II)-範例應用與 4.5新功能【VB/C# 雙語法】

    開賣!下集 -- ASP.NET 4.5 專題實務(II)-範例應用與 4.5新功能[VB/C# 雙語法] 我.....作者都沒拿到書呢! 全台灣最專業的電腦書店 -- 天瓏書局 已經開賣了! 感謝天 ...

  5. 【BUAA软件工程】第一次阅读作业

    BUAA软件工程 第一次阅读作业 项目 内容 这个作业属于哪个课程? 北航软工 这个作业的要求在哪里? 第一次个人作业 我在这个课程的目标是? 学习高效严谨的软件工程开发过程,建立团队意识 这个作业在 ...

  6. [BUAA软工]第1次阅读

    [BUAA软工]第1次阅读 本次作业所属课程: 2019BUAA软件工程 本次作业要求: 第1次个人作业 我在本课程的目标 熟悉和实践软件工程流程,适应团队开发 本次作业的帮助 帮助理解<构建之 ...

  7. [BUAA软工]第一次博客作业---阅读《构建之法》

    [BUAA软工]第一次博客作业 项目 内容 这个作业属于哪个课程 北航软工 这个作业的要求在哪里 第1次个人作业 我在这个课程的目标是 学习如何以团队的形式开发软件,提升个人软件开发能力 这个作业在哪 ...

  8. 线上问题!----------org.apache.catalina.connector.ClientAbortException: java.io.IOException: Broken pipe

    1.问题出现 昨晚项目在上线的时候因为推广的原因,新增的大量请求.在八点的时候. org.apache.catalina.connector.ClientAbortException: java.io ...

  9. [BUAA软工]第零次博客作业---问题回答

    [BUAA软工]第0次博客作业 项目 内容 这个作业属于哪个课程 北航软工 这个作业的要求在哪里 第0次个人作业 我在这个课程的目标是 学习如何以团队的形式开发软件,提升个人软件开发能力 这个作业在哪 ...

随机推荐

  1. Java图片高保真缩放工具类

    Java图片高保真缩放 package com.xindai.auth.service.util; import java.awt.image.BufferedImage; import java.i ...

  2. Uva116 Unidirectional TSP

    https://odzkskevi.qnssl.com/292ca2c84ab5bd27a2a91d66827dd320?v=1508162936 https://vjudge.net/problem ...

  3. NOIP模拟赛 6.29

    2017-6-29 NOIP模拟赛 Problem 1 机器人(robot.cpp/c/pas) [题目描述] 早苗入手了最新的Gundam模型.最新款自然有着与以往不同的功能,那就是它能够自动行走, ...

  4. Leetcode637.Average of Levels in Binary Tree二叉树的层平均值

    给定一个非空二叉树, 返回一个由每层节点平均值组成的数组. class Solution { public: vector<double> averageOfLevels(TreeNode ...

  5. Liferay 7:portlet name

    总结自: https://web.liferay.com/zh/web/user.26526/blog/-/blogs/proper-portlet-name-for-your-portlet-com ...

  6. Spring_代理

    1.代理模式. 2.静态代理原理及实践. 3.动态代理原理及实践. 4.Spring AOP原理及实战. 静态代理原理及实践 package test.staticProxy; // 接口 publi ...

  7. 阿里云SaaS生态战略发布,用宜搭5分钟部署OCR文字识别

    7月26日,在阿里云合作伙伴峰会上,阿里云发布SaaS生态战略:通过SaaS加速器为合作伙伴提供应用开发.集成.上云.售卖的全链路解决方案,提升开发效率和集成效率,缩短商业化周期. 作为阿里SaaS加 ...

  8. JQuery-- 获取元素的宽高、获取浏览器的宽高和垂直滚动距离

    * 能够使用jQuery设置尺寸 * .width() width * .innerWidth() width + padding * .outerWidth() width + padding + ...

  9. nodeJs学习-16 数据字典示例

    1.banner ID title 标题 varchar(32) sub_title 副标题 varchar(16) src 图片地址 varchar(64) 2.文章 ID author 作者 va ...

  10. python已安装包的查看方法和requirements.text的使用

     1.已经安装包的查看方法 命令pip freeze 2. 批量导出命令 pip freeze >requirements.txt 3. 批量导入命令 pip install -r requir ...