UVA11111 Generalized Matrioshkas
来源:互联网 发布:23周b超数据 编辑:程序博客网 时间:2024/06/05 16:28
题目意思就是一排套娃,里面的必须小于外面的,(不能等于)
做法就是用栈模拟,我是匹配到一个正数,并且这是栈顶是正数是 ,然后一直找到找到栈顶是这个数的相反数为止,把正数加起来与这个数比;;
代码有点乱。。不太想动了,,,
#include<iostream>#include<string>#include<stack>#include<stdio.h>#include<string.h>using namespace std;int main () {char ch;long long num[100000];int w = 1;while (cin >> num[0]) {if (num[0] > 0) {cout<<":-( Try again."<<endl;continue;}stack<long long > sta;int i = 1;int z = 0 ;int f = 0 ;bool find = true;int count = 0;bool b = true;ch = getchar();for( i = 1 ;;i++) {cin >> num[i];ch = getchar();if (ch == '\n')break;}for (int k = 0;k <= i;k++){if(num[k] > 0)z++;else f++;}if (z != f) {cout<<":-( Try again."<<endl;continue;}if ( i % 2 == 0) {cout<<":-( Try again."<<endl;continue;}for (int j = 0; j <= i ; j++) {if (num[j] < 0) {sta.push(num[j]);continue;}if (num[j] > 0 && sta.top() < 0 && sta.top() == -num[j]) {sta.push(num[j]);continue;}if(num[j] > 0 && sta.top() < 0 && sta.top() != -num[j] ) {cout<<":-( Try again."<<endl;b = false;break;}while (sta.top() != -num[j]) {if(sta.top() > 0)count += sta.top();sta.pop();if (sta.empty())break;}if(sta.empty()) {find = false;}sta.push(num[j]);if (count >= num[j])find = false;count = 0;}if(b == false)continue;if(find == true)cout <<":-) Matrioshka!"<<endl;elsecout<<":-( Try again."<<endl;memset (num,0,sizeof(num));while (!sta.empty()) sta.pop();find = true;}return 0;}
0 0
- UVA11111- Generalized Matrioshkas
- UVA11111 Generalized Matrioshkas
- uva11111 Generalized Matrioshkas (模拟 + 栈)
- Generalized Matrioshkas
- poj3195 Generalized Matrioshkas(栈)
- uva 11111 - Generalized Matrioshkas
- UVa 11111 Generalized Matrioshkas
- uva 11111 - Generalized Matrioshkas
- uva 11111 - Generalized Matrioshkas
- UVa 11111 - Generalized Matrioshkas
- 11111 - Generalized Matrioshkas
- uva 11111 - Generalized Matrioshkas
- UVa 11111 - Generalized Matrioshkas
- UVaOJ11111---Generalized Matrioshkas
- UVA-11111-Generalized Matrioshkas
- uva 11111 - Generalized Matrioshkas
- uva-11111 Generalized Matrioshkas
- UVa 11111 - Generalized Matrioshkas
- android.intent.category.LAUNCHER 具体作用
- C++中利用stringstream或者c_str()进行int型与string型char*类型转换
- 数的计数
- HDU 2141Can you find it(二分查找)
- 卦爻彖象의 辭
- UVA11111 Generalized Matrioshkas
- try块和异常处理 和调试技术
- GB18030汉字编码范围
- HDU 2199 Can you solve this equation(二分查找)
- HDU 2844 Coins (动规)
- ZOJ3211--Dream City
- php——学习笔记,杂记
- 常用函数之检测目录、多级目录创建
- 色可冽(seaclean)重金属捕捉剂伴侣CMTRAPER--QY-ZP02