Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- using namespace std;
- int main() {
- list<int> llista;
- int codi, nombre;
- while (cin >> codi >> nombre and codi!=0) {
- if (codi == -1) {
- list<int>::iterator it = llista.begin();
- while (it != llista.end() and (*it)<nombre) ++it; //Ordeno la lista de menor a mayor :)
- llista.insert(it,nombre); //pero al parecer al jutge le parece "poco eficiente" >:v
- }
- else if (codi == -2) {
- list<int>::iterator it = llista.begin();
- while (it!=llista.end() and (*it)!=nombre) ++it;
- if (it != llista.end()) llista.erase(it);
- }
- double mitjana=0;
- for (list<int>::iterator it = llista.begin(); it!=llista.end(); ++it) mitjana += (*it);
- if (not llista.empty()) {
- mitjana /= llista.size();
- cout << *llista.begin() << " " << *(--llista.end()) << " " << mitjana << endl;
- }
- else cout << "0" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment