#include <iostream> #include <vector> using namespace std; int main() { short outputLength = 0; vector<short> numbers; cin >> outputLength; int singleNumber = 0; for (int i = 0; i < outputLength; ++i) { cin >> singleNumber; numbers.emplace_back(singleNumber); } short a = 0; short b = 1; short c = 2; vector<short> buc; int sum = 0; //while (a < outputLength) //{ // sum += numbers[a]; // buc.push_back(sum); // // while (b < outputLength) // { // sum += numbers[b]; // buc.push_back(sum); // // while (c < outputLength) // { // sum += numbers[c]; // buc.push_back(sum); // // c++; // } // // //a++; // //b++; // //c = b + 1; // sum = 0; // b++; // } //} auto begin = 0; while (begin < outputLength) { while (a < outputLength) { sum += numbers[a]; buc.push_back(sum); a++; } begin++; a = begin; sum = 0; } // cout << buc.size(); long long result = 0; for (auto i = 0; i < buc.size(); ++i) { for (auto j = i + 1; j < buc.size(); ++j) { for (auto k = j + 1; k < buc.size(); ++k) { if (buc[i] + buc[j] + buc[k] == 0) { result++; } } } } cout << result; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | #include <iostream> #include <vector> using namespace std; int main() { short outputLength = 0; vector<short> numbers; cin >> outputLength; int singleNumber = 0; for (int i = 0; i < outputLength; ++i) { cin >> singleNumber; numbers.emplace_back(singleNumber); } short a = 0; short b = 1; short c = 2; vector<short> buc; int sum = 0; //while (a < outputLength) //{ // sum += numbers[a]; // buc.push_back(sum); // // while (b < outputLength) // { // sum += numbers[b]; // buc.push_back(sum); // // while (c < outputLength) // { // sum += numbers[c]; // buc.push_back(sum); // // c++; // } // // //a++; // //b++; // //c = b + 1; // sum = 0; // b++; // } //} auto begin = 0; while (begin < outputLength) { while (a < outputLength) { sum += numbers[a]; buc.push_back(sum); a++; } begin++; a = begin; sum = 0; } // cout << buc.size(); long long result = 0; for (auto i = 0; i < buc.size(); ++i) { for (auto j = i + 1; j < buc.size(); ++j) { for (auto k = j + 1; k < buc.size(); ++k) { if (buc[i] + buc[j] + buc[k] == 0) { result++; } } } } cout << result; } |