Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <queue>
- #include "utils.PRO2"
- void ordenar(queue<int>& n, int& min, int& max) {
- queue<int> s;
- s = n;
- n.pop();
- for (int i = 0; i <= n.size(); ++i) {
- if (n.front() > max) max = n.front();
- if (n.front() < min) min = n.front();
- n.pop();
- }
- n = s;
- }
- int main() {
- queue <int> n;
- int m = readint();
- double mitjana = 0.0;
- int num = 0;
- while (m > -1002 and m < 1001) {
- int min, max;
- if (m == -1001) {
- if (not n.empty()) {
- mitjana = mitjana - n.front();
- num = num - 1;
- n.pop();
- }
- }
- else if (m != -1001) {
- num += 1;
- mitjana += m;
- n.push(m);
- }
- if (not n.empty()) {
- if (num == 1) min = max = n.front();
- else ordenar(n, min, max);
- cout << "min: " << min;
- cout << " max: " << max;
- cout << " mitjana: " << mitjana/num << endl;
- }
- else if (n.empty()) cout << "0" << endl;
- m = readint();
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement