blob: 518378e63f0ff87bc5e94091cf3ad8bf22398d67 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#include <stdio.h>
#include <stdlib.h>
int main()
{
int t;
long n, i, j;
long long res;
char *s = malloc(1000001), x;
scanf("%d", &t);
while (t--) {
scanf("%ld", &n);
fgets(s, n, stdin);
res = n * (n + 1) / 2;
scanf("%s %c", s, &x);
for (i = 0; i < n; ++i) {
if (s[i] == x)
continue;
for (j = i; j < n && s[j] - x; ++j);
res -= (j - i) * (j - i + 1) / 2;
i = j;
}
printf("%lld\n", res);
}
return 0;
}
|