diff options
Diffstat (limited to 'codechef/CountSubstrings')
| -rw-r--r-- | codechef/CountSubstrings/inp | 0 | ||||
| -rwxr-xr-x | codechef/CountSubstrings/main | bin | 0 -> 24688 bytes | |||
| -rw-r--r-- | codechef/CountSubstrings/main.cpp | 18 | ||||
| -rw-r--r-- | codechef/CountSubstrings/main_input0.txt | 5 | ||||
| -rw-r--r-- | codechef/CountSubstrings/main_output0.txt | 2 |
5 files changed, 25 insertions, 0 deletions
diff --git a/codechef/CountSubstrings/inp b/codechef/CountSubstrings/inp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/codechef/CountSubstrings/inp diff --git a/codechef/CountSubstrings/main b/codechef/CountSubstrings/main Binary files differnew file mode 100755 index 0000000..16c37e0 --- /dev/null +++ b/codechef/CountSubstrings/main 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; + } +} diff --git a/codechef/CountSubstrings/main_input0.txt b/codechef/CountSubstrings/main_input0.txt new file mode 100644 index 0000000..dcf608b --- /dev/null +++ b/codechef/CountSubstrings/main_input0.txt @@ -0,0 +1,5 @@ +2 +4 +1111 +5 +10001 diff --git a/codechef/CountSubstrings/main_output0.txt b/codechef/CountSubstrings/main_output0.txt new file mode 100644 index 0000000..24350e0 --- /dev/null +++ b/codechef/CountSubstrings/main_output0.txt @@ -0,0 +1,2 @@ +10 +3 |
