Untitled
plain_text
a month ago
930 B
2
Indexable
Never
long long calculateHash(const string &str) { const int p = 131; const long long m = 1e9 + 7; long long hashValue = 0; for (char c : str) { hashValue = (hashValue * p + c) % m; } return hashValue; } vector<int> authEvents(vector<vector<string>> events) { vector<int> result; string password; for (const vector<string> &event : events) { if (event[0] == "setPassword") { password = event[1]; } else if (event[0] == "authorize") { long long hashAttempt = stoll(event[1]); long long hashPassword = calculateHash(password); long long hashPasswordWithA = calculateHash(password + "a"); if (hashAttempt == hashPassword || hashAttempt == hashPasswordWithA) { result.push_back(1); } else { result.push_back(0); } } } return result; }