Ответ:
#include <iostream>
#include <vector>
int main()
{
std::vector<int> arr;
int n, j = -1, sum = 0, x;
std::cin >> n;
for (int i = 0; i<n; i++) {
std::cin >> x;
arr.push_back(x);
}
for (int i = arr.size()-1; i>=0; i--)
if (arr[i] == 0) {
j = i;
break;
if (j == -1)
std::cout << "error";
else {
for (int i = j + 1; i<arr.size(); i++)
sum += arr[i];
std::cout << sum;
Объяснение:
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Ответ:
#include <iostream>
#include <vector>
int main()
{
std::vector<int> arr;
int n, j = -1, sum = 0, x;
std::cin >> n;
for (int i = 0; i<n; i++) {
std::cin >> x;
arr.push_back(x);
}
for (int i = arr.size()-1; i>=0; i--)
if (arr[i] == 0) {
j = i;
break;
}
if (j == -1)
std::cout << "error";
else {
for (int i = j + 1; i<arr.size(); i++)
sum += arr[i];
std::cout << sum;
}
}
Объяснение: