-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
176 lines (175 loc) · 5.34 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include <iostream>
#include "libull.h"
#include "account.h"
#include <vector>
#include <cstdio>
#include <fstream>
#include <cstring>
int main() {
// int timer=0;
// freopen("3.in","r",stdin);
// freopen("myout","w",stdout);
visitor *m;
visitor v;customer c;worker w;boss b;
m=&b;
std::ifstream in("judge");
if (!in) {
m->useradd("root","sjtu",7,"root");
std::ofstream out("judge");
out.close();
}
in.close();
std::string order;
while(std::cin>>order) {
if(std::cin.eof()) return 0;
std::string tmp1,tmp2,tmp3;
if (order == "su") {
std::cin>>tmp1;
std::string password_;
char tmp=std::cin.get();
if (tmp== '\n') {
m->su(tmp1.c_str());
}
else {
std::cin>>password_;
m->su(tmp1.c_str(),password_.c_str());
}
if(!log.empty()) current=log.top();
if(current.privilege==0||log.empty()) m=&v;
else if(current.privilege==1) m=&c;
else if (current.privilege==3) m=&w;
else if(current.privilege==7) m=&b;
} else if (order == "logout") {
m->logout();
if(current.privilege==0||log.empty()) m=&v;
else if(current.privilege==1) m=&c;
else if (current.privilege==3) m=&w;
else if(current.privilege==7) m=&b;
}else if(order=="register"){
std::string tmp[5];
int i=0;
while(std::cin.get()!='\n'){
std::cin>>tmp[i];
++i;
}
if(i!=3) {
std::cout<<"Invalid\n";
continue;
}
// if(i>3){
// for(int j=3;j<i;++j){
// tmp[2]+=" ";
// tmp[2]+=tmp[j];
// }
// }
m->Register(tmp[0].c_str(), tmp[1].c_str(), tmp[2].c_str());
}else if(order=="passwd"){
std::cin>>tmp1>>tmp2;
char tmp=std::cin.get();
if(tmp=='\n'){
if(current.privilege==7&&!log.empty()) {
m->passwdd(tmp1.c_str(), tmp2.c_str());
}
else std::cout<<"Invalid\n";
}
else {
std::cin>>tmp3;
m->passwd(tmp1.c_str(),tmp2.c_str(),tmp3.c_str());
}
}else if(order=="useradd"){
std::string tmper[4]={"","","",""};
int i=0;
while(std::cin.get()!='\n'){
std::cin>>tmper[i];
++i;
}
if(tmper[3]==""||i!=4) {
std::cout<<"Invalid\n";
continue;
}
else {
try {
int tmp = atoi(tmper[2].c_str());
m->useradd(tmper[0].c_str(), tmper[1].c_str(), tmp, tmper[3].c_str());
}catch(...){
std::cout<<"Invalid\n";
}
}
}else if(order=="delete"){
std::cin>>tmp1;
m->delete_(tmp1.c_str());
}else if(order=="show"){
char a=std::cin.get();
if(a=='\n') m->show("all");
else {
std::cin >> tmp1;
if(tmp1=="finance") {
char b=std::cin.get();
if(b=='\n') m->show_finance(-1);
else {
int tmp4;
std::cin>>tmp4;
m->show_finance(tmp4);
}
}
else m->show(tmp1.c_str());
}
}else if(order=="buy"){
int tmp4;
try {
std::cin >> tmp1 >> tmp4;
m->buy(tmp1.c_str(), tmp4);
}
catch(...){
std::cout<<"Invalid\n";
continue;
}
}else if(order=="select"){
std::cin>>tmp1;
m->select(tmp1.c_str());
}else if(order=="modify"){
if(!current.selected||current.privilege<=1||log.empty()) {
while(std::cin.get()!='\n'){
std::cin>>tmp1;
}
std::cout<<"Invalid\n";
continue;
}
else {
bool flag=0;
char a=std::cin.get();
while (a != '\n') {
if (a == ' ' && !flag) flag = 1;
else if (a == ' ') {
m->modify(tmp1.c_str());
tmp1 = "";
}
else tmp1 += a;
a = std::cin.get();
}
m->modify(tmp1.c_str());
}
}else if(order=="import"){
int tmp4;double tmp5;
std::cin>>tmp1>>tmp2;
try {
tmp4 = atoi(tmp1.c_str());
tmp5 = std::stod(tmp2.c_str());
}catch (...){
std::cout<<"Invalid\n";
continue;
}
m->import(tmp4,tmp5);
}
else if(order=="exit"||order=="quit"){
return 0;
}
else {
while(std::cin.get()!='\n'){
std::cin>>tmp1;
}
std::cout<<"Invalid\n";
}
}
return 0;
}