aboutsummaryrefslogtreecommitdiff
path: root/codechef/CountSubstrings/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'codechef/CountSubstrings/main.cpp')
-rw-r--r--codechef/CountSubstrings/main.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/codechef/CountSubstrings/main.cpp b/codechef/CountSubstrings/main.cpp
new file mode 100644
index 0000000..8ee40d2
--- /dev/null
+++ b/codechef/CountSubstrings/main.cpp
@@ -0,0 +1,18 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ int tt;
+ cin >> tt;
+ while (tt--) {
+ int n;
+ cin >> n;
+ string s;
+ cin >> s;
+ long long x = count(s.begin(), s.end(), '1');
+ cout << (x * (x+1)) /2 << endl;
+ }
+}