博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT_A1051
阅读量:4322 次
发布时间:2019-06-06

本文共 3080 字,大约阅读时间需要 10 分钟。

第一次未AC代码:

#include 
#include
#include
using namespace std;string str;stack
s;int main(void){ freopen("in.txt","r",stdin); int n,m,k; scanf("%d%d%d",&n,&m,&k); //input char c = getchar(); for(int j = 1; j <= k; j++){ while(!s.empty()) s.pop(); //初始化 getline(cin, str); //输入 for(string::iterator it = str.begin(); it < str.end(); it++){ if(*it == ' ') str.erase(it); //消掉空格 } //处理第一个数 int count = 0,tmp; if((str[0] - '0') > n){ printf("NO\n"); continue; } else{ for(int i = 1; i <= (str[0] - '0'); i++) s.push(i); tmp = s.top(); s.pop(); count++; } while(count < str.size()){ if(s.empty()){ for(int i = tmp + 1; i <= (str[count] - '0'); i++) s.push(i); if(s.size() > n) break; else{ tmp = s.top(); s.pop(); count++; } } else{ if((str[count] - '0') == s.top()){ s.pop(); count++; } else if((str[count] - '0') > tmp){ for(int i = tmp + 1; i <= (str[count] - '0'); i++) s.push(i); if(s.size() > n) break; else{ tmp = s.top(); s.pop(); count++; } } else break; } } if(s.empty()) printf("YES\n"); else printf("NO\n"); } fclose(stdin); return 0;}

 

AC代码:

#include 
#include
#include
using namespace std;const int maxn = 1010;int a[maxn];stack
s;int main(void){ freopen("in.txt","r",stdin); int m,n,k; scanf("%d%d%d",&m,&n,&k); while(k--){ bool sign; int tmp = 1; while(!s.empty()){ //初始化栈 s.pop(); } for(int i = 1; i <= n; i++){ //输入弹出序列 scanf("%d",&a[i]); } for(int i = 1; i <= n; i++){ s.push(i); if(s.size() > m){ //判断是否符合长度 sign = false; break; } while(!s.empty() && s.top() == a[tmp]){ tmp++; s.pop(); } } if(s.empty()) sign = true; else sign = false; if(sign) printf("YES\n"); else printf("NO\n"); } fclose(stdin); return 0;}

 

转载于:https://www.cnblogs.com/phaLQ/p/10461189.html

你可能感兴趣的文章
PHP开源搜索引擎
查看>>
12-FileZilla-响应:550 Permission denied
查看>>
ASP.NET MVC 3 扩展生成 HTML 的 Input 元素
查看>>
LeetCode 234. Palindrome Linked List
查看>>
编译HBase1.0.0-cdh5.4.2版本
查看>>
结构体指针
查看>>
迭代器
查看>>
Food HDU - 4292 (结点容量 拆点) Dinic
查看>>
Ubuntu安装Sun JDK及如何设置默认java JDK
查看>>
[经典算法] 排列组合-N元素集合的M元素子集
查看>>
Codeforces 279D The Minimum Number of Variables 状压dp
查看>>
打分排序系统漫谈2 - 点赞量?点赞率?! 置信区间!
查看>>
valgrind检测linux程序内存泄露
查看>>
MSP430(F149)学习笔记——红外接收
查看>>
cef3的各个接口你知道几个
查看>>
Hadoop以及组件介绍
查看>>
1020 Tree Traversals (25)(25 point(s))
查看>>
第一次作业
查看>>
“==”运算符与equals()
查看>>
单工、半双工和全双工的定义
查看>>