-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavgofmax.cpp
73 lines (68 loc) · 1.47 KB
/
avgofmax.cpp
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
#include <iostream>
#include <bits/stdc++.h>
#include <stdlib.h>
#include <cmath>
#include <string.h>
using namespace std;
int main()
{
vector<int> oddgt, maxgt;
string str;
int x;
while (true)
{
getline(cin, str);
x = stoi(str);
if (x > 0)
{
if (x % 2 == 1)
{
oddgt.push_back(x);
}
else
{
if (oddgt.size() > 0)
{
make_heap(oddgt.begin(), oddgt.end());
maxgt.push_back(oddgt.front());
oddgt.clear();
}
}
}
else
break;
}
int sum = 0;
for (int j : maxgt)
sum += j;
cout << (sum / maxgt.size());
return 0;
}
/*
int main(){
vector<int> oddgt,maxgt;
string str;
int x;
while(true)
{
getline(cin,str);
x=stoi(str);
if(x>0){
if(x%2==1){
oddgt.push_back(x);
}
else { if(oddgt.size()>0){
//make_heap(oddgt.begin(),oddgt.end());
maxgt.push_back(*max_element(oddgt.begin(),oddgt.end()));
oddgt.clear();}
}}
else
break;
}
int sum=0;
//for (int j:maxgt) sum+=j;
sum=accumulate(maxgt.begin(),maxgt.end(),0);
cout<<(sum/maxgt.size());
return 0;
}
*/