模拟栈的过程,一开始我是用的cin来判断每行的每一个数字,然后判断回车结束。有一个点会超时,答案用数组先记录序列的方法非常好。有一个注意点就是访问s.top()的时候先要保证s。size()>0,这点和数组是一样的。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int m,n,k;
  4. int arr[];
  5. int main()
  6. {
  7. stack<int>st;
  8. scanf("%d %d %d", &m, &n, &k);
  9. int i;
  10. while (k--)
  11. {
  12. bool flag = true;
  13. int current = ;
  14. for (i = ; i <= n; i++)
  15. {
  16. scanf("%d", &arr[i]);
  17. }
  18. while (!st.empty())
  19. {
  20. st.pop();
  21. }
  22. for (i = ;i<=n; i++)
  23. {
  24. st.push(i);
  25. if (st.size()>m)
  26. {
  27. flag = false;
  28. break;
  29. }
  30. while (current <= n&&st.size()>&&st.top() == arr[current])
  31. {
  32. st.pop();
  33. current++;
  34. }
  35. }
  36. if (st.size() == && flag == true)
  37. {
  38. printf("YES\n");
  39. }
  40. else
  41. printf("NO\n");
  42. }
  43. }

pat 1051Pop Sequence的更多相关文章

  1. PAT Perfect Sequence (25)

    题目描写叙述 Given a sequence of positive integers and another positive integer p. The sequence is said to ...

  2. PAT 1085 Perfect Sequence

    PAT 1085 Perfect Sequence 题目: Given a sequence of positive integers and another positive integer p. ...

  3. PAT 1085 Perfect Sequence[难]

    1085 Perfect Sequence (25 分) Given a sequence of positive integers and another positive integer p. T ...

  4. PAT 解题报告 1051. Pop Sequence (25)

    1051. Pop Sequence (25) Given a stack which can keep M numbers at most. Push N numbers in the order ...

  5. PAT 1140 Look-and-say Sequence

    1140 Look-and-say Sequence (20 分)   Look-and-say sequence is a sequence of integers as the following ...

  6. PAT A1140 Look-and-say Sequence (20 分)——数学题

    Look-and-say sequence is a sequence of integers as the following: D, D1, D111, D113, D11231, D112213 ...

  7. PAT 甲级 1085 Perfect Sequence

    https://pintia.cn/problem-sets/994805342720868352/problems/994805381845336064 Given a sequence of po ...

  8. PAT 甲级 1051 Pop Sequence

    https://pintia.cn/problem-sets/994805342720868352/problems/994805427332562944 Given a stack which ca ...

  9. 【PAT】1051 Pop Sequence (25)(25 分)

    Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and p ...

随机推荐

  1. netstat实现原理

    因为最近接手的项目是基于嵌入式Linux openwrt的,一开始以为会跟之前的服务器开发没什么大的区别,但是遇到问题去分析的时候才发现,工具链还是有些差别的,openwrt的netstat是属于一个 ...

  2. idea checkout 项目

    1. 2.添加一个连接 选择远程目录checkout  , 然后选择本地目录   但是这样会创建一个新的projectwindow  如果要创建为module的话  1.手动引入从svn check的 ...

  3. Groovy 和 Gradle

    0.Groovy和Gradle是什么关系? Gradle,自动化构建工具,通过简单编写Groovy脚本,便可进行依赖管理并完成项目构建: 1. Groovy有什么用? 脚本+Java代码: 2. Gr ...

  4. 第四百一十六节,Tensorflow简介与安装

    第四百一十六节,Tensorflow简介与安装 TensorFlow是什么 Tensorflow是一个Google开发的第二代机器学习系统,克服了第一代系统DistBelief仅能开发神经网络算法.难 ...

  5. php -- new self() 和 new static

    看一段摘自网上的代码 class A { public static function get_self() { return new self(); } public static function ...

  6. AES和RSA加解密的Python用法

    AES AES 是一种对称加密算法,用key对一段text加密,则用同一个key对密文解密, from Crypto import Random from Crypto.Hash import SHA ...

  7. python列表的切片操作允许索引超出范围

    其余的不说,列表切片操作允许索引超出范围:

  8. Linux 访问权限

    [TOC] Linux访问权限 Linux用户和用户组 查看当前用户用命令who am i 用命令id username可以显示指定用户的用户id.用户组id(GID).和所属附加群组的信息. 所有的 ...

  9. OpenGL矩阵变换,坐标空间变换

  10. Scala 按名称参数调用函数 与 =>的用法

    转自:http://blog.csdn.net/shenxiaoming77/article/details/54835679 通常情况下,函数的参数是传值参数:即参数的值在它被传递给函数之前被确定. ...