#include #include #include #include #include #include #include std::set read_file(std::string const& file) { std::ifstream ifs { file }; return { std::istream_iterator { ifs }, std::istream_iterator { } }; } int main() { auto receipt = read_file("receipt.txt"); auto payments = read_file("payments.txt"); auto total_out = std::accumulate(std::begin(receipt), std::end(receipt), 0); auto total_in = std::accumulate(std::begin(payments), std::end(payments), 0); if (total_out != total_in) { std::cout << "Payments doesn't match total cost" << std::endl; } std::cout << "Incorrect payments:" << std::endl; std::set_difference(std::begin(payments), std::end(payments), std::begin(receipt), std::end(receipt), std::ostream_iterator(std::cout, "\n")); }