Advertisement
srtgguy

Untitled

May 23rd, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4. #include <set>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     vector<string> results;
  12.  
  13.     int n;
  14.     cin >> n;
  15.     map<string, string> system;
  16.     set<string> logged;
  17.     for (int i = 0; i < n; i++)
  18.     {
  19.         string operation, username, password;
  20.         cin >> operation;
  21.         if (operation == "register")
  22.         {
  23.             cin >> username >> password;
  24.             if (system.find(username) == system.end())
  25.             {
  26.                 cout << "success: new user added" << endl;
  27.                 system[username] = password;
  28.             }
  29.             else
  30.             {
  31.                 cout << "fail: user already exists" << endl;
  32.             }
  33.         }
  34.         if (operation == "login")
  35.         {
  36.             cin >> username >> password;
  37.             if (system.find(username) == system.end())
  38.             {
  39.                 cout << "fail: no such user" << endl;
  40.             }
  41.             if (system.find(username) != system.end())
  42.             {
  43.                  if (system[username] == password && logged.find(username) != logged.end())
  44.                  {
  45.                      cout << "fail: already logged in" << endl;
  46.                  }
  47.                  if (system[username] == password && logged.find(username) == logged.end())
  48.                  {
  49.                     cout << "success: user logged in" << endl;
  50.                     logged.insert(username);
  51.                  }
  52.                  if (system[username] != password)
  53.                  {
  54.                      cout << "fail: incorrect password" << endl;
  55.                  }
  56.             }
  57.         }
  58.         if (operation == "logout")
  59.         {
  60.             cin >> username;
  61.             if (system.find(username) == system.end())
  62.             {
  63.                 cout << "fail: no such user" << endl;
  64.             }
  65.             else
  66.             {
  67.                 if (logged.find(username) == logged.end())
  68.                 {
  69.                     cout << "fail: already logged out" << endl;
  70.                 }
  71.                 else
  72.                 {
  73.                     cout << "success: user logged out" << endl;
  74.                     logged.erase(username);
  75.                 }
  76.             }
  77.         }
  78.     }
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement