ZOJ 3654 Letty's Math Class 模拟 难度:0
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4844
题意:给你一个只包含中括号和正整数,+,-,结果在longlong范围内的公式和两个备选答案,
如果答案中有9,第一个是9选A,否则选B
否则,如果第一个是正确答案,输出B,否则输出A
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cctype>
#define clr(x,y) memset(x, y, sizeof x)
#include <cmath>
using namespace std;
const int maxn=2e3+3;
typedef long long ll;
char maz[maxn]; long long read(int& head){
//printf("read start from %d ",head);
long long ans=0;
while(isalnum(maz[head])){
ans*=10;
ans+=maz[head]-'0';
head++;
}
// printf("end at %d ans = %lld\n",head,ans);
return ans;
}
typedef pair<long long ,int > p;
p calc(int st){
long long ans=0;
int cnt=1,ind =st;
for(;maz[ind]!=0&&maz[ind]!=']';){
if(maz[ind]=='-'){
cnt=-1;
ind ++;
//printf("calc ind %d cnt -1\n",ind);
}
else if(maz[ind]=='+'){
ind++;
}
else if(isalnum(maz[ind])){
ans+=cnt*read(ind);
cnt=1;
//printf("calc ind %d cnt 1 ans%lld \n",ind,ans);
}
else if(maz[ind]=='['){
ind++;
p tmp=calc(ind);
ans+=cnt*tmp.first;
ind=tmp.second+1;
cnt=1;
}
}
//printf("calc start at %d end at %d ans = %lld\n",st,ind,ans);
return p(ans,ind);
} int main(){
//freopen("input.txt","r",stdin);
while(scanf("%s",maz)==1){
long long a,b;
scanf("%lld%lld",&a,&b);
if(a==9){
puts("A");
continue;
}
else if(b==9){
puts("B");
continue;
}
long long ans=calc(0).first;
if(ans==a){
puts("B");
}
else puts("A");
}
return 0;
}
ZOJ 3654 Letty's Math Class 模拟 难度:0的更多相关文章
- ZOJ 2477 Magic Cube 暴力,模拟 难度:0
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1477 用IDA*可能更好,但是既然时间宽裕数据简单,而且记录状态很麻烦,就直接 ...
- LeetCode 6 ZigZag Conversion 模拟 难度:0
https://leetcode.com/problems/zigzag-conversion/ The string "PAYPALISHIRING" is written in ...
- POJ 1573 Robot Motion 模拟 难度:0
#define ONLINE_JUDGE #include<cstdio> #include <cstring> #include <algorithm> usin ...
- POJ 2632 Crashing Robots 模拟 难度:0
http://poj.org/problem?id=2632 #include<cstdio> #include <cstring> #include <algorith ...
- POJ 1068 Parencodings 模拟 难度:0
http://poj.org/problem?id=1068 #include<cstdio> #include <cstring> using namespace std; ...
- 快速切题 sgu115. Calendar 模拟 难度:0
115. Calendar time limit per test: 0.25 sec. memory limit per test: 4096 KB First year of new millen ...
- 快速切题 poj 2993 Emag eht htiw Em Pleh 模拟 难度:0
Emag eht htiw Em Pleh Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2806 Accepted: ...
- 快速切题 poj 1002 487-3279 按规则处理 模拟 难度:0
487-3279 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 247781 Accepted: 44015 Descr ...
- java web学习总结(二十一) -------------------模拟Servlet3.0使用注解的方式配置Servlet
一.Servlet的传统配置方式 在JavaWeb开发中, 每次编写一个Servlet都需要在web.xml文件中进行配置,如下所示: 1 <servlet> 2 <servlet- ...
随机推荐
- 百度之星复赛Astar Round3
拍照 树状数组(SB了).求出静止状态下,每个点能看到多少个向右开的船c1[i],多少个向左开的船c2[i]. max{c1[i] + c2[j], (满足i <= j) }即为答案.从后往前 ...
- Java后端开发
Java后端开发 名称 内容 基本框架 Spring.Mybatis Linux服务器 数据库优化 消息服务 rabbitMQ.activeMq rocketMq 缓存服务 memcached ...
- JavaWeb学习计划
1 HTML2 CSS3 JavaScript4 XML5 Tomcat6 Servlet7 HTTP8 Cookie Session9 JSP10 JSTL11 MySQL12 JDBC13 过滤器 ...
- C语言下动态库相互调用
前段时间需要完成多个模块业务,而这些模块的接口都是一样的,于是为了方便管理就把每个模块都根据接口封装成了SO库,这里就留下SO库调用样例 SO库源文件代码: //TestSo.c #include & ...
- Linux命令(1) - 查看内存使用情况: free -hm
使用"free -hm"命令查看linux服务器的内存使用状况,其中-h表示人性化显示,-m表示将内存显示为M:
- ie、火狐、谷歌浏览器,光标定位问题
IE:不管该行有没有文字,光标高度与font-size一致. FF:该行有文字时,光标高度与font-size一致.该行无文字时,光标高度与input的height一致. Chrome:该行无文字时, ...
- maven寻找jar
http://mvnrepository.com/artifact/org.springframework/spring-context
- Unity5 新功能解析--物理渲染与standard shader
Unity5 新功能解析--物理渲染与standard shader http://blog.csdn.net/leonwei/article/details/48395061 物理渲染是UNITY5 ...
- MySQL和OneSQL并行插入性能对比
按照我的作风,没图说个啥 环境 下面是受叶金荣老师的启发把相关环境交代清楚 MySQL和OneSQL的关键参数配置如下 数据库 sync_binlog innodb_flush_log_at_trx_ ...
- 【转】 STL中的set容器的一点总结
1.关于set C++ STL 之所以得到广泛的赞誉,也被很多人使用,不只是提供了像vector, string, list等方便的容器,更重要的是STL封装了许多复杂的数据结构算法和大量常用数据结构 ...