Description:

Count is one of WNJXYK’s favorite tasks. Recently, he had a very long string and he wondered that how many substrings which contains exactly one kind of lowercase in this long string. But this string is so long that he had kept counting for several days. His friend Kayaking wants to help him, so he turns to you for help.

Input

The input starts with one line contains exactly one positive integer TT which is the number of test cases. 
Each test case contains one line with a string which you need to do a counting task on.

Output

For each test case, output one line containing “y” where y is the number of target substrings.

Sample Input

3
qwertyuiop
qqwweerrttyyuuiioopp
aaaaaaaaaa

Sample Output

10
30
55

题意:

给出一个字符串求包含有多少单个字母组成的连续子串,规律题。

找到连续的单个字符的长度然后通过等差数列前n项和公式求出组合。

AC代码:

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
char a[100010];
int i,j,k;
int n,m;
ll ans;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%s",&a);
int len=strlen(a);
ll cnt;
ans=0;
for(i=0; i<len; i++)
{
cnt=1;
while(i+1<len)
{
if(a[i]==a[i+1])
{
cnt++;
i++;
}
else
break;
}
ans+=cnt*(cnt+1)/2;
}
printf("%lld\n",ans);
}
return 0;
}