Created
April 1, 2019 09:41
-
-
Save axayjha/4e642ea46adcaefb8dcc9fa2d4ff002d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
int count_zero_seq(vector <int> seq) | |
{ | |
int n = seq.size(); | |
int count = 0; | |
for (int len = 1; len <= n; len++) | |
{ | |
for (int i = 0; i <= n - len; i++) | |
{ | |
int summ = 0; | |
int j = i + len - 1; | |
for (int k = i; k <= j; k++) | |
summ += seq[k]; | |
if (summ == 0) count ++; | |
} | |
} | |
return count; | |
} | |
int main() | |
{ | |
int n; | |
vector<int> seq; | |
cin >> n; | |
for (int i = 0; i < n; i++) | |
{ | |
int j; | |
cin >> j; | |
seq.push_back(j); | |
} | |
cout << count_zero_seq(seq) << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment