题目是栈操作

#include "bits/stdc++.h"
using namespace std;

int main()
{
    string m;
    while(cin >> m)
    {
        stack<int>b;
        int len = m.length();
        for(int i=0,k = 1;i < len ;i++){
            if(m[i] == 'P'){
                b.push(k++);
            }
            else
            {
                if(!b.empty()){
                    cout << b.top() << " ";
                    b.pop();
                }
                else
                {
                    cout << "error";
                    break;
                }

            }
        }
        cout << endl;
    }
}

最后发现是在输出error后没有及时的break,造成后续的输出,比较欣慰的是oj提出了“输出超限”的提示,找到了问题所在。

相关文章:

  • 2021-08-20
  • 2021-10-30
  • 2021-07-04
  • 2022-12-23
  • 2021-12-19
  • 2021-11-27
  • 2021-10-17
  • 2022-01-10
猜你喜欢
  • 2022-12-23
  • 2022-01-10
  • 2021-12-10
  • 2021-08-18
  • 2021-07-14
  • 2022-12-23
  • 2021-04-18
相关资源
相似解决方案