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- ...
随机推荐
- 理解odbc
1.解决什么样的问题?不同的数据库产品,具有不同的特性,也就是方言.因此应用程序针对不同的数据库产品,编写不同的代码.如果换了一个数据库产品,还需要重新编写数据库交互部分,不具备扩展和移植.odbc对 ...
- Android是如何绘制View的
当一个activity获得焦点时, 它会被要求绘制它的布局. Android框架将处理绘制的过程, 但是activity必须提供它的布局体系的根节点. 绘制将从根节点开始, 根节点被要求测量和绘制布局 ...
- 【转载】Linux系统,设置Oracle开机启动,待整理
http://www.cnblogs.com/mophee/archive/2013/06/03/3115805.html
- c++(vs上)与g++(linux下)对于++操作的汇编代码解读
先来看一个代码,估计很多同学都碰到过其中的某一个. #include <stdio.h> #include <iostream> using namespace std; in ...
- 阿里云+wordpress搭建个人博客网站
[正文] 在阿里云上搭建使用个人博客主要分为以下几个步骤: 1.购买阿里云ECS主机 2.购买域名 3.申请备案 4.环境配置 5.安装wordpress 6.域名解析 声明一下,本人对服务器端的知识 ...
- Machine Learning – 第2周(Linear Regression with Multiple Variables、Octave/Matlab Tutorial)
Machine Learning – Coursera Octave for Microsoft Windows GNU Octave官网 GNU Octave帮助文档 (有900页的pdf版本) O ...
- 安卓手机与电脑无线传输文件(利用ftp服务)
安卓手机与电脑无线传输文件(利用ftp服务) 手机与电脑无线传输文件,手机开启ftp服务,电脑能够对手机内全部文件进行全方位管理,包括上传.下载.新建.删除等,而且手机和电脑能够双向传输,很方便.手机 ...
- MySQL初级培训
按照一个MySQL DBA在工作中接触到部分的先后顺序,编排培训目录如下. 字段选取 int , decimal, char , varchar , blob ,timestamp SQL优化 exp ...
- JUnit org.junit.runner.Request.classWithoutSuiteMethod解决方法
欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...
- python 练习 25
Python 语言允许在一个循环体里面嵌入另一个循环. Python for 循环嵌套语法: for iterating_var in sequence: for iterating_var in s ...