Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <iostream>
- #include <map>
- #include <algorithm>
- #include <pcrecpp.h>
- int main(int, char** )
- {
- const pcrecpp::RE re("\"GET (?:https?://.+?/)?(.+?\\.mp3) "
- "HTTP/1\\.[01]\" \\d{3} (\\d+)");
- std::map<std::string, std::pair<long, long>> stat;
- for( std::string line; std::getline(std::cin, line); )
- {
- std::string fname;
- long size;
- if( re.PartialMatch( line, &fname, &size ) )
- {
- auto it = stat.find( fname );
- if( it == stat.end() )
- stat.emplace( fname, std::make_pair(size, size) );
- else
- {
- const auto sum = it->second.first + size;
- const auto max = std::max( it->second.second, size );
- it->second = std::make_pair( sum, max );
- }
- }
- }
- for( const auto& info: stat )
- {
- const double sum = info.second.first;
- const auto max = std::max(info.second.second, 1L); // avoid division by zero
- const auto downloads = sum / max;
- std::cout << "Key: " << info.first << " downloads: " << downloads
- << " (max size: " << max << ")" << std::endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment