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. Python学习(5)条件语句

    目录 Python 条件语句 Python 简单的语句组 Python 条件语句 Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块. 可以通过下图来简单了 ...

  2. php用curl调用接口方法,get和post两种方式

    首先是客户端执行方法ApiModel.php: <?php /** * 模拟post进行url请求 * @param string $url * @param array $post_data ...

  3. asp.net 柱形图

    在vs中,如果要使用柱形图,我们大多数使用第三方提供的插件,所以必须要引用样式,这里我使用的是Highcharts-4.1.9插件,百度一下就可以下载到. 关键的js代码: <script sr ...

  4. Hadoop与Spark比较

    先看这篇文章:http://www.huochai.mobi/p/d/3967708/?share_tid=86bc0ba46c64&fmid=0 直接比较Hadoop和Spark有难度,因为 ...

  5. centos JDK安装

    第一步:查看Linux自带的JDK是否已安装 (卸载centOS已安装的1.4) 安装好的CentOS会自带OpenJdk,用命令 java -version ,会有下面的信息: java versi ...

  6. J2EE 第二阶段项目之编写代码(三)

    我的任务就是项目统计. 1 效益统计 1 教育效益统计表 (教育效益统计表,增,改,查看,查) 2 农牧林效益统计表 (农牧林效益统计表,增,改,查看,查) 3 乡村效益统计表    (乡村效益统计表 ...

  7. 网站QQ导航

    <a href="http://wpa.qq.com/msgrd?v=3&uin=[color=Red]361983679[/color]&site=qq&me ...

  8. Sqlserver_sql注入

    随着B/S模式应用开发的发展,使用这种模式编写应用程序的程序员也越来越多.但是由于这个行业的入门门槛不高,程序员的水平及经验也参差不齐,相当大一部分程序员在编写代码的时候,没有对用户输入数据的合法性进 ...

  9. 转!大端模式&小端模式

    大端模式&小端模式   在C语言中除了8位的char型之外,还有16位的short型,32位的long型(要看具体的编译器),对于位数大于8位的处理器,例如16位或者32位的处理器,由于寄存器 ...

  10. 为什么删不掉date模块

    显示是field pending deletion一看report里面的field list并没有xxx_date_xxx,只好跑到数据库才看到一个field_date_test当时并没有把这个字段当 ...