【JZOJ4840】【NOIP2016提高A组集训第4场11.1】小W砍大树
2024-08-27 14:39:13
题目描述
数据范围
解法
模拟。
代码
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<iostream>
#define ll long long
using namespace std;
const char* fin="form.in";
const char* fout="form.out";
const int inf=0x7fffffff;
const int maxn=40007;
char ch;
bool stack[maxn];
int t,tot,y;
int main(){
freopen(fin,"r",stdin);
freopen(fout,"w",stdout);
ch=getchar();
while (1){
y=0;
while (ch!='(' && ch!=')' && ch!='F' && ch!='T'){
ch=getchar();
y++;
if (y==10) return 0;
}
t++;
tot=0;
stack[tot]=false;
while (ch=='(' || ch==')' || ch=='F' || ch=='T'){
if (ch=='('){
tot++;
stack[tot]=(tot&1?true:false);
}else if (ch==')'){
if (tot&1) stack[tot-1]|=stack[tot];
else stack[tot-1]&=stack[tot];
tot--;
}else if (ch=='F'){
if (tot%2) stack[tot]=false;
}else if (tot%2==0) stack[tot]=true;
ch=getchar();
}
if (stack[0]) printf("%d. true\n",t);
else printf("%d. false\n",t);
}
return 0;
}
启发
利用getchar()连续多次失效来判断文件输入结束。
最新文章
- SVN需要忽略的文件类型
- SpringMVC介绍之Validation
- http://blog.csdn.net/liuqinstudy/article/details/8281498
- 2016年10月13日 星期四 --出埃及记 Exodus 18:24
- MySQL5.7.13源码编译安装指南(转)
- 2017年浙江理工大学程序设计竞赛校赛 题解&;源码(A.水, D. 简单贪心 ,E.数论,I 暴力)
- Imcash:一边大裁员,一边大扩招,你能否成为区块链人才中的7%?
- Docker 启动,进入容器,查看log命令
- 蒟阵P3390 【模板】矩阵快速幂
- LeetCode169 求众数
- Java学习08 (第一遍) - SpringMVC
- KD-树(下)
- Selenium2+python自动化73-定位的坑:class属性有空格
- Python笔记:Python中is和==的区别
- 20155218《网络对抗》Exp3 免杀原理与实践
- 慕课网价值149《前端JavaScript面试技巧》笔记大公开——适应群体(学生或应届毕业生)
- unity3d 材质概述 ---- shader
- JNative用法注意事项
- 基于aop的redis自动缓存实现
- (一)mvc与mvvm设计模式
热门文章
- IDEA常用插件整理
- Spring cloud properties与yml配置说明
- 2019.10.26 csp-s模拟测试88 反思总结
- LA3882 And Then There Was One
- Javascript-new Date() 与 Date() 的区别
- 洛谷 P3956 棋盘
- [Array]414. Third Maximum Number
- pc端拖拽
- node学习记录——搭建web服务器
- warning: deprecated conversion from string constant to &#39;char*