Ответы
Ответ дал:
0
Ответ:
#include "stdafx.h"
#include <iostream>
#include <stack>
#include <random>
using namespace std;
int main()
{
random_device r;
mt19937 gen(r());
uniform_int_distribution<> dist(-10, 0);
stack<int> st;
const int n = 20;
int j = 0, sum = 0;
cout << "Stack:\n";
for (int i = 0; i < n; i++) {
int c = dist(gen);
cout << c << "\n";
st.push(c);
}
while (!st.empty()) {
int c = st.top();
st.pop();
j++;
if (j == 4) { sum += c; j = 0; }
}
st.push(sum);
cout << "Sum = " << st.top() << "\n";
}
0
Вас заинтересует
1 год назад
2 года назад
2 года назад
7 лет назад
7 лет назад
8 лет назад