ThaiPeen

timus 2002

May 21st, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. #include<string>
  4. #include<vector>
  5. using namespace std;
  6. const int MAXN = 150;
  7. int a[MAXN];
  8. string p[100], o[100];
  9. void reg(string a, int n) {
  10.     string b, c;
  11.     bool q = 0;
  12.     int j = 9;
  13.     while (a[j] != ' ') {
  14.         b += a[j];
  15.         j++;
  16.     }
  17.     j++;
  18.     for (int i = 0; i < n; i++) {
  19.         if (p[i] == "") {
  20.             p[i] = b;
  21.             break;
  22.         }
  23.         if (p[i] == b) {
  24.             q = 1;
  25.             break;
  26.         }
  27.     }
  28.     if (q == 1) {
  29.         cout << "fail: user already exists\n";
  30.         return;
  31.     }
  32.     while (a[j] != '\0') {
  33.         c += a[j];
  34.         j++;
  35.     }
  36.     for (int i = 0; i < n; i++) {
  37.         if (o[i] == "") {
  38.             p[i] = b;
  39.             break;
  40.         }
  41.     }
  42.     cout << "success: new user added\n";
  43. }
  44. void login(string a, int n) {
  45.     string b, c;
  46.     int j = 6;
  47.     while (a[j] != ' ') {
  48.         b += a[j];
  49.         j++;
  50.     }
  51.     for (int i = 0; i < n; i++) {
  52.         if (p[i] == b) {
  53.             break;
  54.         }
  55.         if (p[i] == "") {
  56.             cout << "fail: no such user";
  57.             return;
  58.         }
  59.     }
  60.     j++;
  61.     while (a[j] != '\0') {
  62.         c += a[j];
  63.         j++;
  64.     }
  65.     for (int i = 0; i < n; i++) {
  66.         if (o[i] == c) {
  67.             cout << "success: user logged in";
  68.             return;
  69.         }
  70.         if (o[i] == "") {
  71.             cout << "fail: incorrect password";
  72.             return;
  73.         }
  74.     }
  75. }
  76. int main() {
  77.     int n;
  78.     string a[100];
  79.     cin >> n;
  80.     for (int i = 0; i < n; i++) {
  81.         getline(cin, a[i]);
  82.         if (a[i][0] == 'r') {
  83.             reg(a[i], n);
  84.             continue;
  85.         }
  86.         if (a[i][3] == 'i') {
  87.             login(a[i], n);
  88.         }
  89.     }
  90.     system("pause");
  91. }
Advertisement
Add Comment
Please, Sign In to add comment