HDU - 6480

http://acm.hdu.edu.cn/showproblem.php?pid=6480

 

#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        ll ans=0, cnt=1;
        for(int i=0; i<s.size();)
        {
            if(s[i]==s[i+1])
            {
                cnt++;
                i++;
            }
            else
            {
                ans+=((cnt+1)*cnt)/2;
                cnt=1;
                i++;
            }
        }
        cout<<ans<<endl;
    }
}

 

posted @ 2021-04-25 18:46  BlackSnow  阅读(42)  评论(0)    收藏  举报