本文共 597 字,大约阅读时间需要 1 分钟。
#include#include using namespace std;int main(){ stack s; int n; while (cin >> n) { int a[100000]; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); if (!s.empty() && a[i] < s.top()) { s.pop(); num--; } sum += num; num++; s.push(a[i]); } while (!s.empty()) s.pop(); cout << sum << endl; }}
注:请注意上述代码已剥离除<div>
、<pre>
等HTML标签外的所有无关内容,仅保留原始代码核心逻辑。代码已经过轻微优化,调整部分注释和格式,使其更易读。上述代码功能与原文一致。
转载地址:http://btnez.baihongyu.com/