csu - 1537: Miscalculation (模拟题)
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1537
因为给出的式子是必定合法的,只要用两个栈分别保存符号和数字.算出答案后和从左至右算的答案比对即可.
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue> #define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long
#define inf 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0) #define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("din.txt", "r", stdin)
#define Write() freopen("dout.txt", "w", stdout); using namespace std; int main()
{
//freopen("a.txt","r",stdin);
char s[];
int num;
scanf("%s",s);
scanf("%d",&num);
stack<int>s1;
stack<char>s2;
int l=strlen(s);
for(int i=;i<l;i++)
{
if(s[i]>=''&&s[i]<='') s1.push(s[i]-'');
else if(s[i]=='*')
{
int x=s1.top();s1.pop();
int y=s[i+]-'';
s1.push(x*y);
i++;
}
else s2.push('+');
}
while(!s2.empty())
{
int x=s1.top();s1.pop();
int y=s1.top();s1.pop();
s1.push(x+y);
s2.pop();
}
int sum=s[]-'';
for(int i=;i<l;i++)
{
if(s[i]=='+') sum=sum+(s[i+]-'');
else if(s[i]=='*') sum=sum*(s[i+]-'');
}
//printf("%d %d\n",s1.top(),sum);
if(s1.top()==sum&&sum==num) printf("U\n");
else if(s1.top()!=num&&sum!=num) printf("I\n");
else if(s1.top()==num&&sum!=num) printf("M\n");
else if(s1.top()!=num&&sum==num) printf("L\n");
return ;
}
csu - 1537: Miscalculation (模拟题)的更多相关文章
- csu 1312 榜单(模拟题)
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1312 1312: 榜单 Time Limit: 1 Sec Memory Limit: 128 ...
- poj 1008:Maya Calendar(模拟题,玛雅日历转换)
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64795 Accepted: 19978 D ...
- poj 1888 Crossword Answers 模拟题
Crossword Answers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 869 Accepted: 405 D ...
- CodeForces - 427B (模拟题)
Prison Transfer Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)
The Android University ACM Team Selection Contest Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里 ...
- 全国信息学奥林匹克联赛 ( NOIP2014) 复赛 模拟题 Day1 长乐一中
题目名称 正确答案 序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer. ...
- UVALive 4222 Dance 模拟题
Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...
- cdoj 25 点球大战(penalty) 模拟题
点球大战(penalty) Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/2 ...
- Educational Codeforces Round 2 A. Extract Numbers 模拟题
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
随机推荐
- RabbitMQ六:通过routingkey模拟日志
序言 本章文章进入深入了解RabbiMQ,平时项目中我们经常用到记录日志,常见的不外乎:Info.debug.warn.Error. 情境进入:先简单说一下我们需求,我们开发过程中会遇到很多日 ...
- js拿到焦点所在的标签对象
通过 document.activeElement 此时是js对象,如果要调用jQuery的API那么就转换成jquery对象 $(document.activeElement)
- 修改vim注释字体颜色
vim /etc/vimrc#最后一行新增代码块hi comment ctermfg=6 注:注释用 " 标注 PS:默认的注释颜色是4 然后有0,1,2,3,4,5,6,7来选择.可以除 ...
- 15年第六届蓝桥杯第七题_手链样式_(stl_string)
手链样式 小明有3颗红珊瑚,4颗白珊瑚,5颗黄玛瑙.他想用它们串成一圈作为手链,送给女朋友.现在小明想知道:如果考虑手链可以随意转动或翻转,一共可以有多少不同的组合样式呢? 请你提交该整数.不要填写任 ...
- Flutter走过的坑(持续更新)
1 Target of URI doesn't exist 'package:flutter/material.dart' 官方下载的flutter中有一个example文件夹,里面有很多flutte ...
- CE工具里自带的学习工具--第一关
点击[下一步],进入第二关
- java_lock锁
lock锁是一个接口,jdk5.0新增的接口: 在线程中创建一个他的实现类对象Reentrantlock,默认为fals可以改为true,改为true后是有序的 把操作共享资源的代码放入try中,在t ...
- 01Oracle Database
Oracle Database Oracle Database又名Oracle RDBMS简称Oracle是甲骨文公司的一款关系数据库管理系统. Oracle Website.
- 解决dom4j加载xml文件性能慢的问题
在代码中使用: 1: DocumentHelper.parseText 2: SAXReader reader = new SAXReader(); Document extdocument = re ...
- Myeclipse快速排版的快捷键
Myeclipse快速排版的快捷键 1.全选 ctrl+a 2.排版 ctrl+i