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- ...
随机推荐
- mysql 有关的文件
1.在linux上安装好mysql之后,存在很多mysql有关的文件. 2./etc/rc.d/init.d/mysql 是mysql服务的启动脚本,是对mysqld_safe的封装,mysqld_s ...
- Volley框架的流程图分析
接着上一篇Volley框架的使用,这一篇主要主要讲Volley框架运作的原理.主要使用流程图来叙述,简单的分析了整个流程的过程,具体的请参考源代码或者查看我上一篇在文章末尾添上的链接. 一 ...
- 阿里云+wordpress搭建个人博客网站
[正文] 在阿里云上搭建使用个人博客主要分为以下几个步骤: 1.购买阿里云ECS主机 2.购买域名 3.申请备案 4.环境配置 5.安装wordpress 6.域名解析 声明一下,本人对服务器端的知识 ...
- OpenGL的glViewport视口变换函数详解[转]
调用glViewPort函数来决定视见区域,告诉OpenGL应把渲染之后的图形绘制在窗体的哪个部位.当视见区域是整个窗体时,OpenGL将把渲染结果绘制到整个窗口. void glViewPort(G ...
- linux mount命令的用法详细解析
挂接命令(mount)首先,介绍一下挂接(mount)命令的使用方法,mount命令参数非常多,这里主要讲一下今天我们要用到的.命令格式:mount [-t vfstype] [-o options] ...
- IIS_各种问题
IIS7中默认是已经加载了脚本映射处理.但今天装了个WIN7,装好IIS后却发现没有.于是手动去这安装,在添加html映射时提示:模块列表中必须要有IsapiModule或cgiModule 因为 I ...
- js文字上下滚动代码
<div id="dome"> <div id="dome1"> <ul class="express"> ...
- 数据库中间件mycat简单入门
当在项目中mysql数据库成为瓶颈的时候,我们一般会使用主从复制,分库分表的方式来提高数据库的响应速度,比如mysql主从复制,在没有数据库中间件的情况下,我们只能由开发工程师在程序中控制,这对于一个 ...
- 理解Cookie和Session机制
转载: 理解Cookie和Session机制 会话(Session)跟踪是Web程序中常用的技术,用来跟踪用户的整个会话.常用的会话跟踪技术是Cookie与Session.Cookie通过在客户端记录 ...
- 任性,新建对象不用new
先看最简单的一个例子: window.meng = window.meng || {}; (function () { /** * * @param {Number}width * @param {N ...