uva-11111-栈
注意输入和输出的结果
-9 -7 -2 2 -3 -2 -1 1 2 3 7 9
-9 -7 -2 2 -3 -1 -2 2 1 3 7 9
-9 -7 -2 2 -3 -1 -2 3 2 1 7 9
-100 -50 -6 6 50 100
-100 -50 -6 6 45 100
-10 -5 -2 2 5 -4 -3 3 4 10
-9 -5 -2 2 5 -4 -3 3 4 9
-10 -5 -3 3 -1 1 5 -4 4 10
10
-10 10
-10
:-) Matrioshka!
:-( Try again.
:-( Try again.
:-) Matrioshka!
:-( Try again.
:-) Matrioshka!
:-( Try again.
:-) Matrioshka!
:-( Try again.
:-) Matrioshka!
:-( Try again.
#include <iostream> #include <sstream> #include<memory.h> #include<stdio.h> using namespace std; const int N = 10000; struct stack {int a[N];int index;stack(){index = 0;}void push(int i){a[index++] = i;}int pop(){int i = a[--index];return i;} }; int main() {int n;string str;while (getline(cin, str)){istringstream is(str);int hasInt = 0;stack s;memset(s.a, 0, sizeof(s.a));int error = 0;while (is >> n){hasInt++;if (n < 0)s.push(n);else{int t = 0;while (s.index){int j = s.pop();if (j > 0)t += j;else{if (j != n * -1)error = 1;break;}}if (t < n && !error)s.push(n);elsebreak;}}if (!hasInt){//cout << ":-( Try again." << endl;continue;}if (hasInt == 1){cout << ":-( Try again." << endl;continue;}if (error || s.index != 1)cout << ":-( Try again." << endl;else if (s.index == 1){if (s.pop() > 0)cout << ":-) Matrioshka!" << endl;elsecout << ":-( Try again." << endl;}}return 0; }
转载于:https://www.cnblogs.com/shuiyonglewodezzzzz/p/7345754.html
uva-11111-栈相关推荐
- 初学者acm的练习题指南
上机练习题参考题 忘了在哪找的啦~~希望对大家有帮助呦 <!--[if !supportLists]-->1. <!--[endif]-->Programming Bas ...
- 暑期集训4:栈,树,优先队列 例 : UVA - 514
2018学校暑期集训第四天--栈,树,优先队列 例题 -- UVA - 514 Rails There is a famous railway station in PopPush City. ...
- uva计算机水平,UVA 12096 集合栈计算机
UVA 12096 集合栈计算机 题目描述 有一个专门为了集合运算而设计的"集合栈"计算机.该机器有一个初始为空的栈,并且 支持以下操作. PUSH:空集"{}" ...
- Rails UVA - 514(栈)
题目链接:https://vjudge.net/problem/UVA-514 题目大意:右边的火车经过中间的收费站到左边,右边火车进站的秩序是1~n 判断是否能以题中是所给的次序通过 思路:很明 ...
- The SetStack Computer UVA - 12096 集合栈计算机 set集合
题目链接 有一个专门为了集合运算而设计的"集合栈"计算机.该机器有一个初始为空的栈,并且 支持以下操作. PUSH:空集"{}"入栈. DUP:把当前栈顶元素复 ...
- Uva 10074【递推dp】
UVa 10074 题意:求01矩阵的最大子0矩阵. http://www.csie.ntnu.edu.tw/~u91029/MaximumSubarray.html#2 这里说的很清楚.先求Larg ...
- 例题6-2 铁轨(Rails, ACM/ICPC CERC 1997, UVa 514)
栈应用 例题6-2 铁轨(Rails, ACM/ICPC CERC 1997, UVa 514) 错解 1.每次要把栈清空 2.不能用空的栈(栈顶)去比较 #include<iostream&g ...
- UVA 11995 I Can Guess the Data Structure! STL
题目链接: UVA很难登上去吧...... 题目大意: 给你几组输入与输出让你判断是栈,队列, 堆, 还是不确定, 还是哪种也不是 解题思路: 这题看起来很简单, 搞几个标准STL, 和结果一对比就知 ...
- 安全的交互通道 及 栈回塑检查与伪造
第四章:安全的交互通道 消息钩子,Hook游戏消息处理过程,GetKeyState(),GetAsyncKeyState()和GetKeyBoardState()函数,进程间通信. 消息钩子:SetW ...
- UVA - 514:Rails
题目链接:https://vjudge.net/problem/UVA-514 题目分析 题目的意思是给一个栈输入一系列数据,在这个过程中可以出栈,看能否达到某个结果. 刚开始我觉得这个情况好多,因此 ...
最新文章
- 【 MATLAB 】DFS 和 DTFT 之间的关系
- 关于CBitmap,LoadBitmap 的使用
- Android 几种换肤方式和原理分析
- 解决安装DEB包时报错
- linux which命令的使用示例
- PHP的session阻塞问题
- oracle 31693,ORACLE expdp备份与ORA-31693、ORA-02354、ORA-01555
- C++笔记-仿函数(functor)
- 什么是urlencode,什么时候能用到
- 学习python的第五天
- 扩展-视图 View
- tesseract-ocr 识别中文扫描图片
- 计算机组装课上机课干什么,多媒体技术与《计算机组装与维护》课的精彩结合:组装一台多媒体计算机需要哪些部件...
- 蚂蚁课堂-第四期-基于SpringCloud构建微服务电商项目 (无密) 解压密码是多少
- mapreduce详细工作流程
- 在Redhat9下安装Oracle9
- 软件公司 sun公司 Oracle公司
- SSDP(简单服务发现协议)
- 将xlsx内容转成json
- 智慧灯杆项目案例:点亮科技城市!宁波第一个5G智能路段投入使用!
热门文章
- atitit.软件开发方法总结O6
- [转] 全面了解Windows任务管理器
- linux的 0号进程(idle进程) 和 1 号进程(init进程)
- Ember.js入门教程、博文汇总
- Axis-Parallel Rectangle
- 《Scala机器学习》一一2.3 探索与利用问题
- Jexus部署.Net Core项目
- 被动信息收集之RECON-NG(七)
- Android之玩转MPAndroidChart让(折线图、柱形图、饼状图、散列图、雷达图)优雅的舞...
- CentOs配置网卡