代码拉取完成,页面将自动刷新
class AuthenticationManager {
public:
void MapSortOfValue(vector<pair<int,string> >& vec,map<string,int>& m) {
for (map<string, int>::iterator it = m.begin(); it != m.end(); it++)
vec.push_back(make_pair(it->second, it->first));
sort(vec.begin(), vec.end());
}
int t2l;
map<string, int> msg;
AuthenticationManager(int timeToLive) {
t2l = timeToLive;
}
void generate(string tokenId, int currentTime) {
auto it = msg.find(tokenId);
if (it == msg.end()) {
msg.insert({tokenId, currentTime});
it = msg.find(tokenId);
}
else it->second = currentTime;
}
void renew(string tokenId, int currentTime) {
auto it = msg.find(tokenId);
if (it != msg.end()) {
if (it->second + t2l > currentTime)
it->second = currentTime;
else
msg.erase(it);
}
}
int countUnexpiredTokens(int currentTime) {
int ret = 0;
vector<pair<int,string>>v;
MapSortOfValue(v, msg);
cout << currentTime << endl;
int len = v.size();
for (int i = len - 1; i >= 0; i--) {
if (v[i].first + t2l > currentTime)
ret += 1;
else break;
}
return ret;
}
};
/**
* Your AuthenticationManager object will be instantiated and called as such:
* AuthenticationManager* obj = new AuthenticationManager(timeToLive);
* obj->generate(tokenId,currentTime);
* obj->renew(tokenId,currentTime);
* int param_3 = obj->countUnexpiredTokens(currentTime);
*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。