You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
642 B
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 50;
char s[N];
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
scanf("%s", s);
int len = strlen(s);
s[len++] = '#';
ll ans = 0;
int last = 0;
for (int i = 1; i < len; i++)
if (s[i] != s[i - 1])
{
ans += 1ll * (i - last) * (i - last + 1) / 2;
last = i;
}
printf("%lld\n", ans);
}
return 0;
}