Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- #include<string>
- #include<vector>
- using namespace std;
- const int MAXN = 150;
- int a[MAXN];
- string p[100], o[100];
- void reg(string a, int n) {
- string b, c;
- bool q = 0;
- int j = 9;
- while (a[j] != ' ') {
- b += a[j];
- j++;
- }
- j++;
- for (int i = 0; i < n; i++) {
- if (p[i] == "") {
- p[i] = b;
- break;
- }
- if (p[i] == b) {
- q = 1;
- break;
- }
- }
- if (q == 1) {
- cout << "fail: user already exists\n";
- return;
- }
- while (a[j] != '\0') {
- c += a[j];
- j++;
- }
- for (int i = 0; i < n; i++) {
- if (o[i] == "") {
- p[i] = b;
- break;
- }
- }
- cout << "success: new user added\n";
- }
- void login(string a, int n) {
- string b, c;
- int j = 6;
- while (a[j] != ' ') {
- b += a[j];
- j++;
- }
- for (int i = 0; i < n; i++) {
- if (p[i] == b) {
- break;
- }
- if (p[i] == "") {
- cout << "fail: no such user";
- return;
- }
- }
- j++;
- while (a[j] != '\0') {
- c += a[j];
- j++;
- }
- for (int i = 0; i < n; i++) {
- if (o[i] == c) {
- cout << "success: user logged in";
- return;
- }
- if (o[i] == "") {
- cout << "fail: incorrect password";
- return;
- }
- }
- }
- int main() {
- int n;
- string a[100];
- cin >> n;
- for (int i = 0; i < n; i++) {
- getline(cin, a[i]);
- if (a[i][0] == 'r') {
- reg(a[i], n);
- continue;
- }
- if (a[i][3] == 'i') {
- login(a[i], n);
- }
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment