// you can use includes, for example:
#include <algorithm>
#include <iterator>
#include <map>
#include <string>
#include <iostream>
using namespace std;
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
class Duration
{
public:
Duration(int hours, int minutes, int seconds) :
seconds_ ((hours*60*60) + (minutes*60) + seconds)
{
}
template<typename It>
static Duration fromLogLine(It pos) {
int components[3] = {0};
for (auto i = 0; i < 3; i ++) {
components[i] = std::stoi(std::string(pos, pos + 2));
pos += 3;
}
return Duration(components[0], components[1], components[2]);
}
bool operator<(const Duration &other) const {
return seconds_ < other.seconds_;
}
auto seconds() const { return seconds_; }
private:
int seconds_;
};
class Number
{
public:
Number(int number) :
number_ (number)
{
}
template<typename It>
static Number fromLogLine(It pos) {
constexpr auto NUMBER_OFFSET = 9;
constexpr auto PART_SIZE = 3;
constexpr auto PART_OFFSET = 4;
pos += NUMBER_OFFSET;
int number = 0;
for (auto i = 0; i < 3; i ++) {
number *= 1000;
number += std::stoi(std::string(pos, pos+PART_SIZE));
pos += PART_OFFSET;
}
return Number(number);
}
auto number() const { return number_; }
auto operator<(const Number &other) const {
return number_ < other.number_;
}
private:
int number_;
};
class LogEntry
{
public:
LogEntry(Duration duration, Number number) :
duration_ (duration),
number_ (number)
{}
template<typename It>
static LogEntry fromStringRange(It begin, It end) {
return LogEntry(Duration::fromLogLine(begin), Number::fromLogLine(begin));
}
auto& duration() const { return duration_; }
auto& number() const { return number_; }
private:
Duration duration_;
Number number_;
};
class CallLogParser
{
static const auto LINE_LENGTH = 21;
public:
struct iterator {
iterator(std::string::const_iterator iter) : position_(iter) {}
void operator++() {
position_ += LINE_LENGTH;
}
void operator++(int) {
position_ += LINE_LENGTH;
}
bool operator!=(iterator &other) {
return position_ < other.position_;
}
LogEntry operator*() {
return LogEntry::fromStringRange(position_, position_ + LINE_LENGTH - 1);
}
private:
std::string::const_iterator position_;
};
CallLogParser(const std::string &call_log) :
call_log_ (call_log)
{
}
iterator begin() {
return iterator(call_log_.begin());
}
iterator end() {
return iterator(call_log_.end());
}
private:
const std::string &call_log_;
};
class NormalCallCost {
public:
NormalCallCost(LogEntry entry) :
entry_ (entry)
{
}
auto cost() const {
if (entry_.duration() < Duration(0, 5, 0)) {
return entry_.duration().seconds() * 3;
} else {
return ((entry_.duration().seconds() / 60) + 1) * 150;
}
}
void debug_dump() {
std::cout << "Number: " << entry_.number().number() << " seconds: " << entry_.duration().seconds() << " cost: " << cost() << std::endl;
}
private:
LogEntry entry_;
};
int solution(string &S) {
CallLogParser parser(S);
std::map<Number, NormalCallCost> summary;
for(auto call : parser) {
summary[call.number()] = NormalCallCost(call);
}
return 0;
}
Ly8geW91IGNhbiB1c2UgaW5jbHVkZXMsIGZvciBleGFtcGxlOgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8aXRlcmF0b3I+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDxpb3N0cmVhbT4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgovLyB5b3UgY2FuIHdyaXRlIHRvIHN0ZG91dCBmb3IgZGVidWdnaW5nIHB1cnBvc2VzLCBlLmcuCi8vIGNvdXQgPDwgInRoaXMgaXMgYSBkZWJ1ZyBtZXNzYWdlIiA8PCBlbmRsOwoKY2xhc3MgRHVyYXRpb24KewpwdWJsaWM6CiAgICBEdXJhdGlvbihpbnQgaG91cnMsIGludCBtaW51dGVzLCBpbnQgc2Vjb25kcykgOgogICAgICAgIHNlY29uZHNfICgoaG91cnMqNjAqNjApICsgKG1pbnV0ZXMqNjApICsgc2Vjb25kcykKICAgIHsKICAgIH0KICAgIAogICAgdGVtcGxhdGU8dHlwZW5hbWUgSXQ+CiAgICBzdGF0aWMgRHVyYXRpb24gZnJvbUxvZ0xpbmUoSXQgcG9zKSB7CiAgICAgICAgaW50IGNvbXBvbmVudHNbM10gPSB7MH07CiAgICAgICAgCiAgICAgICAgZm9yIChhdXRvIGkgPSAwOyBpIDwgMzsgaSArKykgewogICAgICAgICAgICBjb21wb25lbnRzW2ldID0gc3RkOjpzdG9pKHN0ZDo6c3RyaW5nKHBvcywgcG9zICsgMikpOwogICAgICAgICAgICBwb3MgKz0gMzsKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgcmV0dXJuIER1cmF0aW9uKGNvbXBvbmVudHNbMF0sIGNvbXBvbmVudHNbMV0sIGNvbXBvbmVudHNbMl0pOwogICAgfQogICAgCiAgICBib29sIG9wZXJhdG9yPChjb25zdCBEdXJhdGlvbiAmb3RoZXIpIGNvbnN0IHsKICAgICAgICByZXR1cm4gc2Vjb25kc18gPCBvdGhlci5zZWNvbmRzXzsKICAgIH0KICAgIAogICAgYXV0byBzZWNvbmRzKCkgY29uc3QgeyByZXR1cm4gc2Vjb25kc187IH0KCnByaXZhdGU6CiAgICBpbnQgc2Vjb25kc187Cn07CgpjbGFzcyBOdW1iZXIKewpwdWJsaWM6CiAgICBOdW1iZXIoaW50IG51bWJlcikgOgogICAgICAgIG51bWJlcl8gKG51bWJlcikKICAgIHsKICAgIH0KICAgIAogICAgdGVtcGxhdGU8dHlwZW5hbWUgSXQ+CiAgICBzdGF0aWMgTnVtYmVyIGZyb21Mb2dMaW5lKEl0IHBvcykgewogICAgICAgIGNvbnN0ZXhwciBhdXRvIE5VTUJFUl9PRkZTRVQgPSA5OwogICAgICAgIGNvbnN0ZXhwciBhdXRvIFBBUlRfU0laRSA9IDM7CiAgICAgICAgY29uc3RleHByIGF1dG8gUEFSVF9PRkZTRVQgPSA0OwogICAgICAgIHBvcyArPSBOVU1CRVJfT0ZGU0VUOwogICAgICAgIGludCBudW1iZXIgPSAwOwogICAgICAgIAogICAgICAgIGZvciAoYXV0byBpID0gMDsgaSA8IDM7IGkgKyspIHsKICAgICAgICAgICAgbnVtYmVyICo9IDEwMDA7CiAgICAgICAgICAgIG51bWJlciArPSBzdGQ6OnN0b2koc3RkOjpzdHJpbmcocG9zLCBwb3MrUEFSVF9TSVpFKSk7CiAgICAgICAgICAgIHBvcy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o6c3RyaW5nOjpjb25zdF9pdGVyYXRvciBpdGVyKSA6IHBvc2l0aW9uXyhpdGVyKSB7fQogICAgICAgIAogICAgICAgIHZvaWQgb3BlcmF0b3IrKygpIHsKICAgICAgICAgICAgcG9zaXRpb25fICs9IExJTkVfTEVOR1RIOwogICAgICAgIH0KICAgICAgICAKICAgICAgICB2b2lkIG9wZXJhdG9yKysoaW50KSB7CiAgICAgICAgICAgIHBvc2l0aW9uXyArPSBMSU5FX0xFTkdUSDsKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgYm9vbCBvcGVyYXRvciE9KGl0ZXJhdG9yICZvdGhlcikgewogICAgICAgICAgICByZXR1cm4gcG9zaXRpb25fIDwgb3RoZXIucG9zaXRpb25fOwogICAgICAgIH0KICAgICAgICAKICAgICAgICBMb2dFbnRyeSBvcGVyYXRvciooKSB7CiAgICAgICAgICAgIHJldHVybiBMb2dFbnRyeTo6ZnJvbVN0cmluZ1JhbmdlKHBvc2l0aW9uXywgcG9zaXRpb25fICsgTElORV9MRU5HVEggLSAxKTsKICAgICAgICB9CiAgICAgICAgCiAgICBwcml2YXRlOgogICAgICAgIHN0ZDo6c3RyaW5nOjpjb25zdF9pdGVyYXRvciBwb3NpdGlvbl87CiAgICB9OwoKICAgIENhbGxMb2dQYXJzZXIoY29uc3Qgc3RkOjpzdHJpbmcgJmNhbGxfbG9nKSA6CiAgICAgICAgY2FsbF9sb2dfIChjYWxsX2xvZykKICAgIHsKICAgIH0KICAgIAogICAgaXRlcmF0b3IgYmVnaW4oKSB7CiAgICAgICAgcmV0dXJuIGl0ZXJhdG9yKGNhbGxfbG9nXy5iZWdpbigpKTsKICAgIH0KICAgIAogICAgaXRlcmF0b3IgZW5kKCkgewogICAgICAgIHJldHVybiBpdGVyYXRvcihjYWxsX2xvZ18uZW5kKCkpOwogICAgfQogICAgCnByaXZhdGU6CiAgICBjb25zdCBzdGQ6OnN0cmluZyAmY2FsbF9sb2dfOwp9OwoKY2xhc3MgTm9ybWFsQ2FsbENvc3QgewpwdWJsaWM6CiAgICBOb3JtYWxDYWxsQ29zdChMb2dFbnRyeSBlbnRyeSkgOgogICAgICAgIGVudHJ5XyAoZW50cnkpCiAgICB7CiAgICB9CiAgICAKICAgIGF1dG8gY29zdCgpIGNvbnN0IHsKICAgICAgICBpZiAoZW50cnlfLmR1cmF0aW9uKCkgPCBEdXJhdGlvbigwLCA1LCAwKSkgewogICAgICAgICAgICByZXR1cm4gZW50cnlfLmR1cmF0aW9uKCkuc2Vjb25kcygpICogMzsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICByZXR1cm4gKChlbnRyeV8uZHVyYXRpb24oKS5zZWNvbmRzKCkgLyA2MCkgKyAxKSAqIDE1MDsKICAgICAgICB9CiAgICB9CiAgICAKICAgIHZvaWQgZGVidWdfZHVtcCgpIHsKICAgICAgICBzdGQ6OmNvdXQgPDwgIk51bWJlcjogIiA8PCBlbnRyeV8ubnVtYmVyKCkubnVtYmVyKCkgPDwgIiBzZWNvbmRzOiAiIDw8IGVudHJ5Xy5kdXJhdGlvbigpLnNlY29uZHMoKSA8PCAiIGNvc3Q6ICIgPDwgY29zdCgpIDw8IHN0ZDo6ZW5kbDsKICAgIH0KCnByaXZhdGU6CiAgICBMb2dFbnRyeSBlbnRyeV87Cn07CgppbnQgc29sdXRpb24oc3RyaW5nICZTKSB7CiAgICBDYWxsTG9nUGFyc2VyIHBhcnNlcihTKTsKICAgIHN0ZDo6bWFwPE51bWJlciwgTm9ybWFsQ2FsbENvc3Q+IHN1bW1hcnk7CiAgICAKICAgIGZvcihhdXRvIGNhbGwgOiBwYXJzZXIpIHsKICAgICAgICBzdW1tYXJ5W2NhbGwubnVtYmVyKCldID0gTm9ybWFsQ2FsbENvc3QoY2FsbCk7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0=
In file included from /usr/include/c++/6/bits/stl_map.h:63:0,
from /usr/include/c++/6/map:61,
from prog.cpp:4:
/usr/include/c++/6/tuple: In instantiation of ‘std::pair<_T1, _T2>::pair(std::tuple<_Args1 ...>&, std::tuple<_Args2 ...>&, std::_Index_tuple<_Indexes1 ...>, std::_Index_tuple<_Indexes2 ...>) [with _Args1 = {const Number&}; long unsigned int ..._Indexes1 = {0ul}; _Args2 = {}; long unsigned int ..._Indexes2 = {}; _T1 = const Number; _T2 = NormalCallCost]’:
/usr/include/c++/6/tuple:1579:63: required from ‘std::pair<_T1, _T2>::pair(std::piecewise_construct_t, std::tuple<_Args1 ...>, std::tuple<_Args2 ...>) [with _Args1 = {const Number&}; _Args2 = {}; _T1 = const Number; _T2 = NormalCallCost]’
/usr/include/c++/6/ext/new_allocator.h:120:4: required from ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = std::pair<const Number, NormalCallCost>; _Args = {const std::piecewise_construct_t&, std::tuple<const Number&>, std::tuple<>}; _Tp = std::_Rb_tree_node<std::pair<const Number, NormalCallCost> >]’
/usr/include/c++/6/bits/alloc_traits.h:455:4: required from ‘static void std::allocator_traits<std::allocator<_Tp> >::construct(std::allocator_traits<std::allocator<_Tp> >::allocator_type&, _Up*, _Args&& ...) [with _Up = std::pair<const Number, NormalCallCost>; _Args = {const std::piecewise_construct_t&, std::tuple<const Number&>, std::tuple<>}; _Tp = std::_Rb_tree_node<std::pair<const Number, NormalCallCost> >; std::allocator_traits<std::allocator<_Tp> >::allocator_type = std::allocator<std::_Rb_tree_node<std::pair<const Number, NormalCallCost> > >]’
/usr/include/c++/6/bits/stl_tree.h:543:32: required from ‘void std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_construct_node(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Link_type, _Args&& ...) [with _Args = {const std::piecewise_construct_t&, std::tuple<const Number&>, std::tuple<>}; _Key = Number; _Val = std::pair<const Number, NormalCallCost>; _KeyOfValue = std::_Select1st<std::pair<const Number, NormalCallCost> >; _Compare = std::less<Number>; _Alloc = std::allocator<std::pair<const Number, NormalCallCost> >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Link_type = std::_Rb_tree_node<std::pair<const Number, NormalCallCost> >*]’
/usr/include/c++/6/bits/stl_tree.h:560:4: required from ‘std::_Rb_tree_node<_Val>* std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_create_node(_Args&& ...) [with _Args = {const std::piecewise_construct_t&, std::tuple<const Number&>, std::tuple<>}; _Key = Number; _Val = std::pair<const Number, NormalCallCost>; _KeyOfValue = std::_Select1st<std::pair<const Number, NormalCallCost> >; _Compare = std::less<Number>; _Alloc = std::allocator<std::pair<const Number, NormalCallCost> >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Link_type = std::_Rb_tree_node<std::pair<const Number, NormalCallCost> >*]’
/usr/include/c++/6/bits/stl_tree.h:2196:64: required from ‘std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_emplace_hint_unique(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator, _Args&& ...) [with _Args = {const std::piecewise_construct_t&, std::tuple<const Number&>, std::tuple<>}; _Key = Number; _Val = std::pair<const Number, NormalCallCost>; _KeyOfValue = std::_Select1st<std::pair<const Number, NormalCallCost> >; _Compare = std::less<Number>; _Alloc = std::allocator<std::pair<const Number, NormalCallCost> >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator = std::_Rb_tree_iterator<std::pair<const Number, NormalCallCost> >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<const Number, NormalCallCost> >]’
/usr/include/c++/6/bits/stl_map.h:483:8: required from ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = Number; _Tp = NormalCallCost; _Compare = std::less<Number>; _Alloc = std::allocator<std::pair<const Number, NormalCallCost> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = NormalCallCost; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = Number]’
prog.cpp:173:30: required from here
/usr/include/c++/6/tuple:1590:70: error: no matching function for call to ‘NormalCallCost::NormalCallCost()’
second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...)
^
prog.cpp:147:5: note: candidate: NormalCallCost::NormalCallCost(LogEntry)
NormalCallCost(LogEntry entry) :
^~~~~~~~~~~~~~
prog.cpp:147:5: note: candidate expects 1 argument, 0 provided
prog.cpp:145:7: note: candidate: constexpr NormalCallCost::NormalCallCost(const NormalCallCost&)
class NormalCallCost {
^~~~~~~~~~~~~~
prog.cpp:145:7: note: candidate expects 1 argument, 0 provided
prog.cpp:145:7: note: candidate: constexpr NormalCallCost::NormalCallCost(NormalCallCost&&)
prog.cpp:145:7: note: candidate expects 1 argument, 0 provided