about summary refs log tree commit diff
path: root/codechef/strch.c
diff options
context:
space:
mode:
authorNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-04-15 17:20:41 +0700
committerNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-04-15 17:20:41 +0700
commit887c286cc8228e13f85b587ab92b37e920161eb9 (patch)
tree6528ca8873c4f80b6d13114550615c7a1f1f4afe /codechef/strch.c
parentebb7f33582fb24fe70f13796b88e93b99c243425 (diff)
downloadcp-887c286cc8228e13f85b587ab92b37e920161eb9.tar.gz
Codechef celebrate 4.20 a bit early this year
Diffstat (limited to 'codechef/strch.c')
-rw-r--r--codechef/strch.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/codechef/strch.c b/codechef/strch.c
new file mode 100644
index 0000000..518378e
--- /dev/null
+++ b/codechef/strch.c
@@ -0,0 +1,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;
+}