Repository navigation
Expand file tree
/
Copy pathProga8-1.cpp
More file actions
52 lines (45 loc) · 1.45 KB
/
Copy pathProga8-1.cpp
File metadata and controls
52 lines (45 loc) · 1.45 KB
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
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
setlocale(LC_ALL, "RUS");
int quantityElements;
std::cout << "Ââåäèòå êîëè÷åñòâî ýëåìåíòîâ ìàññèâà: ";
std::cin >> quantityElements;
std::vector<double> arr(quantityElements);
std::cout << "Ââåäèòå ýëåìåíòû ìàññèâà: ";
for (int i = 0; i < quantityElements; ++i) {
std::cin >> arr[i];
}
double negativesSum = 0;
for (const auto& elem : arr) {
if (elem < 0) {
negativesSum += elem;
}
}
int firstZeroIndex = -1;
int lastZeroIndex = -1;
for (int i = 0; i < quantityElements; ++i) {
if (arr[i] == 0) {
if (firstZeroIndex == -1) {
firstZeroIndex = i;
}
lastZeroIndex = i;
}
}
double sumBetweenZeros = 0;
if (firstZeroIndex != -1 && lastZeroIndex != -1 && firstZeroIndex != lastZeroIndex) {
for (int i = firstZeroIndex + 1; i < lastZeroIndex; ++i) {
sumBetweenZeros += arr[i];
}
}
std::sort(arr.begin(), arr.end());
std::cout << "Ñóììà îòðèöàòåëüíûõ ýëåìåíòîâ: " << negativesSum << std::endl;
std::cout << "Ñóììà ýëåìåíòîâ ìåæäó ïåðâûìè íóëÿìè: " << sumBetweenZeros << std::endl;
std::cout << "Óïîðÿäî÷åííûé ìàññèâ: ";
for (const auto& elem : arr) {
std::cout << elem << " ";
}
std::cout << std::endl;
return 0;
}