#include <iostream>
#include <string>
#include <vector>
#include <map>
class Package {
public:
double val;
double calculate_cost(){
return this->val;
}
Package(double val):val(val){}
};
int main(){
std::map<std::string, std::vector<Package*>> packagemap;
//dados de teste
std::vector<Package*> package1;
package1.push_back(new Package(10));
package1.push_back(new Package(15));
package1.push_back(new Package(13));
packagemap.insert(std::make_pair("test1", package1));
std::vector<Package*> package2;
package2.push_back(new Package(20));
package2.push_back(new Package(35));
package2.push_back(new Package(56));
packagemap.insert(std::make_pair("test2", package2));
//calcular o total
double total = 0;
for (auto package_entry : packagemap){
for (auto package_ptr: package_entry.second){
total += package_ptr->calculate_cost();
}
}
std::cout << total;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWFwPgoKY2xhc3MgUGFja2FnZSB7CnB1YmxpYzoKICAgIGRvdWJsZSB2YWw7CiAgICBkb3VibGUgY2FsY3VsYXRlX2Nvc3QoKXsKICAgICAgICByZXR1cm4gdGhpcy0+dmFsOwogICAgfQogICAgUGFja2FnZShkb3VibGUgdmFsKTp2YWwodmFsKXt9Cn07CgppbnQgbWFpbigpewogICAgc3RkOjptYXA8c3RkOjpzdHJpbmcsIHN0ZDo6dmVjdG9yPFBhY2thZ2UqPj4gcGFja2FnZW1hcDsKCiAgICAvL2RhZG9zIGRlIHRlc3RlCiAgICBzdGQ6OnZlY3RvcjxQYWNrYWdlKj4gcGFja2FnZTE7CiAgICBwYWNrYWdlMS5wdXNoX2JhY2sobmV3IFBhY2thZ2UoMTApKTsKICAgIHBhY2thZ2UxLnB1c2hfYmFjayhuZXcgUGFja2FnZSgxNSkpOwogICAgcGFja2FnZTEucHVzaF9iYWNrKG5ldyBQYWNrYWdlKDEzKSk7CiAgICBwYWNrYWdlbWFwLmluc2VydChzdGQ6Om1ha2VfcGFpcigidGVzdDEiLCBwYWNrYWdlMSkpOwoKCiAgICBzdGQ6OnZlY3Rvcj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