Untitled
unknown
c_cpp
2 years ago
865 B
15
Indexable
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <sstream>
#include <iomanip>
#include <chrono>
bool check(const std::vector<std::string>& log) {
std::tm tm = {};
std::istringstream ss(log[2] + " " + log[1]);
ss >> std::get_time(&tm, "%Y-%m-%d %H:%M:%S");
return !ss.fail();
}
std::vector<std::vector<std::string>> solution(const std::vector<std::vector<std::string>>& logs) {
std::map<std::string, std::map<std::string, int>> mapping;
for (const auto& log : logs) {
if (check(log)) {
mapping[log[0]][log[2]]++;
}
}
std::vector<std::vector<std::string>> result;
for (const auto& user : mapping) {
for (const auto& date : user.second) {
result.push_back({user.first, date.first, std::to_string(date.second)});
}
}
return result;
}
Editor is loading...
Leave a Comment