题意:
大模拟,模拟银行操作。
分析:
按题意一个一个操作的进行就好了
ACcode:
#include <bits/stdc++.h>
#include <string>
#define maxn 1000005
#define ll long long
using namespace std;
map<string,int>vis;
struct N{
string id,ps;
ll v;
void init(){///不初始化会发生错误
id="";
ps="";
v=0;
}
}my[maxn];
char s[100];
string t1,t2,t3;
int main(){
int n,tot;
ll add;
while(scanf("%d",&n)!=EOF){
vis.clear();
for(int i=0;i<maxn;++i)my[i].init();
tot=1;
for(int i=0;i<n;++i){
scanf("%s",s);
switch(s[0]){
case 'O':{
cin>>t1>>t2>>add;
if(vis[t1])puts("Account exists.");
else {
vis[t1]=tot;
my[tot].id=t1;
my[tot].ps=t2;
my[tot].v=add;
tot++;
puts("Successfully opened an account.");
}
break;
}
case 'D':{
cin>>t1>>add;
if(vis[t1]){
my[vis[t1]].v+=add;;
puts("Successfully deposited money.");
}
else puts("Account does not exist.");
break;
}
case 'W':{
cin>>t1>>t2>>add;
if(vis[t1]){
int pos=vis[t1];
if(t2!=my[pos].ps)puts("Wrong password.");
else {
if(my[pos].v<add)puts("Money not enough.");
else {
my[pos].v-=add;
puts("Successfully withdrew money.");
}
}
}
else puts("Account does not exist.");
break;
}
case 'T':{
cin>>t1>>t2>>t3>>add;
if(vis[t1]==0||vis[t3]==0)puts("Account does not exist.");
else {
int pos1=vis[t1],pos2=vis[t3];
if(my[pos1].ps!=t2)puts("Wrong password.");
else {
if(my[pos1].v<add)puts("Money not enough.");
else {
my[pos1].v-=add;
my[pos2].v+=add;
puts("Successfully transfered money.");
}
}
}
break;
}
case 'C':{
cin>>t1>>t2;
if(vis[t1]){
int pos=vis[t1];
if(my[pos].ps!=t2)puts("Wrong password.");
else cout<<my[pos].v<<'\12';
}
else puts("Account does not exist.");
break;
}
case 'X':{
cin>>t1>>t2>>t3;
if(vis[t1]){
int pos=vis[t1];
if(my[pos].ps==t2){
my[pos].ps=t3;
puts("Successfully changed password.");
}
else puts("Wrong password.");
}
else puts("Account does not exist.");
break;
}
}
}
cout<<'\12';
}
return 0;
}