Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <map>
- #include <set>
- #include <vector>
- using namespace std;
- int main()
- {
- vector<string> results;
- int n;
- cin >> n;
- map<string, string> system;
- set<string> logged;
- for (int i = 0; i < n; i++)
- {
- string operation, username, password;
- cin >> operation;
- if (operation == "register")
- {
- cin >> username >> password;
- if (system.find(username) == system.end())
- {
- cout << "success: new user added" << endl;
- system[username] = password;
- }
- else
- {
- cout << "fail: user already exists" << endl;
- }
- }
- if (operation == "login")
- {
- cin >> username >> password;
- if (system.find(username) == system.end())
- {
- cout << "fail: no such user" << endl;
- }
- if (system.find(username) != system.end())
- {
- if (system[username] == password && logged.find(username) != logged.end())
- {
- cout << "fail: already logged in" << endl;
- }
- if (system[username] == password && logged.find(username) == logged.end())
- {
- cout << "success: user logged in" << endl;
- logged.insert(username);
- }
- if (system[username] != password)
- {
- cout << "fail: incorrect password" << endl;
- }
- }
- }
- if (operation == "logout")
- {
- cin >> username;
- if (system.find(username) == system.end())
- {
- cout << "fail: no such user" << endl;
- }
- else
- {
- if (logged.find(username) == logged.end())
- {
- cout << "fail: already logged out" << endl;
- }
- else
- {
- cout << "success: user logged out" << endl;
- logged.erase(username);
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement