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的更多相关文章

  1. ZOJ 2477 Magic Cube 暴力,模拟 难度:0

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1477 用IDA*可能更好,但是既然时间宽裕数据简单,而且记录状态很麻烦,就直接 ...

  2. LeetCode 6 ZigZag Conversion 模拟 难度:0

    https://leetcode.com/problems/zigzag-conversion/ The string "PAYPALISHIRING" is written in ...

  3. POJ 1573 Robot Motion 模拟 难度:0

    #define ONLINE_JUDGE #include<cstdio> #include <cstring> #include <algorithm> usin ...

  4. POJ 2632 Crashing Robots 模拟 难度:0

    http://poj.org/problem?id=2632 #include<cstdio> #include <cstring> #include <algorith ...

  5. POJ 1068 Parencodings 模拟 难度:0

    http://poj.org/problem?id=1068 #include<cstdio> #include <cstring> using namespace std; ...

  6. 快速切题 sgu115. Calendar 模拟 难度:0

    115. Calendar time limit per test: 0.25 sec. memory limit per test: 4096 KB First year of new millen ...

  7. 快速切题 poj 2993 Emag eht htiw Em Pleh 模拟 难度:0

    Emag eht htiw Em Pleh Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2806   Accepted:  ...

  8. 快速切题 poj 1002 487-3279 按规则处理 模拟 难度:0

    487-3279 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 247781   Accepted: 44015 Descr ...

  9. java web学习总结(二十一) -------------------模拟Servlet3.0使用注解的方式配置Servlet

    一.Servlet的传统配置方式 在JavaWeb开发中, 每次编写一个Servlet都需要在web.xml文件中进行配置,如下所示: 1 <servlet> 2 <servlet- ...

随机推荐

  1. mysql 逻辑架构

    1.mysql是基于网络的客户端/服务器架构,服务器上层是连接线程,解析器,查询缓存,下层是存储引擎. 2.每个客户端连接,服务器都有一个对应的线程,这个线程只为这个连接查询服务,高版本的mysql支 ...

  2. js图片跑马灯效果

    <style. type="text/css">body{margin:0px auto; padding:0px;}ul,li{margin:0px; padding ...

  3. strcpy, memcpy, memset函数

    一. strcpy函数 原型声明:char *strcpy(char* dest, const char *src);   头文件:#include <string.h> 和 #inclu ...

  4. JavaWeb学习计划

    1 HTML2 CSS3 JavaScript4 XML5 Tomcat6 Servlet7 HTTP8 Cookie Session9 JSP10 JSTL11 MySQL12 JDBC13 过滤器 ...

  5. Poco C++——JSON解析

    #include <iostream> #include "Poco/Dynamic/Var.h" #include "Poco/Dynamic/Pair.h ...

  6. JavaScript设计模式-单例模式、模块模式(转载 学习中。。。。)

    (转载地址:http://technicolor.iteye.com/blog/1409656) 之前在<JavaScript小特性-面向对象>里面介绍过JavaScript面向对象的特性 ...

  7. Eclipse 设置文件的默认打开方式

    web开发中,我们在编辑JSP/xml的时候,会碰到一个非常郁闷的事,直接双击打开的JSP页面,当我们在编辑的时候会到处跳,这个我是深有体会,所以我们就用右击 open with,但是久而久之我们会感 ...

  8. Hbase之插入数据

    /** * Created by similarface on 16/8/17. */ import org.apache.hadoop.conf.Configuration; import org. ...

  9. Jni的一个异常

    UnsatisfiedLinkError:No implementation found for java.lang.String com.skymaster.hs.test4.MainActivit ...

  10. WAP调用微信支付https://pay.weixin.qq.com/wiki/doc/api/wap.php?chapter=15_1

    公司做的一个购物网站 之前微信版的网站要搬在webView上   可是微信支付是个问题 , 在外部浏览器怎么都发不起微信请求 , 原因是因为页面调用的微信浏览器自带JSAPI 在外部浏览器无法调用,但 ...