题目链接
这题虽然过了,但写的太丑了,欣赏一下别人简短代码
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 200010;
int n;
int q[N],s[N];
int tt=0;
signed main()
{
cin>>n;
for(int i=0;i<n;i++)
{
int x;cin>>x;
q[++tt]=x;
if(tt==1||q[tt]!=q[tt-1])s[tt]=1;
else s[tt]=s[tt-1]+1;
if(s[tt]==x)tt-=x;
cout<<tt<<'\n';
}
}
这篇博客展示了如何使用C++通过高效算法更新序列中连续重复元素的计数,代码简洁易懂,适合提升代码美感。
145

被折叠的 条评论
为什么被折叠?



