牛客多校第八场

。_饼干妹妹 提交于 2019-11-26 22:20:27

https://ac.nowcoder.com/acm/contest/888#question

 

 

B

签到题,代码可真短。

 

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

const int maxn=1e5+10;
#define ll long long
int maxx[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    ll ans=0;
    ll sum=0;
    int t;
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&t);
        sum=sum-maxx[t]+i;
        maxx[t]=i;
        ans=ans+sum;
    }
    printf("%lld",ans);
}
View Code

 

 

 

签到题

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

const int maxn=1e5+10;
char s[maxn];
int main()
{
    scanf("%s",s+1);
    int len=strlen(s+1);
    int ans=0;
    stack<char> st;
    for(int i=1; i<=len; i++)
    {
        st.push(s[i]);
        if(st.size()>=3)
        {
            char c1=st.top();st.pop();
            char c2=st.top();st.pop();
            char c3=st.top();st.pop();
            if(c1==c2&&c2==c3)
                ans++;
            else
            {
                st.push(c3);st.push(c2);st.push(c1);
            }
        }
    }
    printf("%d",ans);



}
View Code

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!