I have been doing the count substrings problem which is from the July contest. My code is getting the wrong answer and I have no idea what is going wrong. Below is my code:
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
int T, N;
string str;
scanf("%d", &T);
while (T--) {
scanf("%d", &N);
int counter = 0;
cin >> str;
for (int i = 0; i < N; i++) {
if (str[i] - '0' == 1) counter++;
}
printf("%d\n", (counter * (counter + 1)) / 2);
}
return 0;
}