http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2167
因为所有客户资料是与账户名挂钩的,所以以一个map做映射,做账户名和一个结构体的映射,结构体是cipher(string)和balance(int)。
#include <iostream> #include <map> #include <string> #include <stdio.h> using namespace std; typedef struct pwd_bal { string password; int balance; }p; int main() { int t; cin>>t; map<string, p> a; while(t--) { char c; cin>>c; if(c == 'O') { string name; p temp; cin>>name>>temp.password>>temp.balance; if(a.insert(make_pair(name,temp)).second) { cout<<"Successfully opened an account."<<endl; } else { cout<<"Account exists."<<endl; } } else if(c == 'D') { string name; int money; cin>>name>>money; map<string,p>::iterator it = a.find(name); if(it != a.end()) { (it->second).balance += money; cout<<"Successfully deposited money."<<endl; } else { cout<<"Account does not exist."<<endl; } } else if(c == 'W') { string name, password; int money; cin>>name>>password>>money; map<string,p>::iterator it = a.find(name); if(it != a.end()) { if((it->second).password == password) { if((it->second).balance >= money) { (it->second).balance -= money; cout<<"Successfully withdrew money."<<endl; } else { cout<<"Money not enough."<<endl; } } else { cout<<"Wrong password."<<endl; } } else { cout<<"Account does not exist."<<endl; } } else if(c == 'T') { string name1, password, name2; int money; cin>>name1>>password>>name2>>money; map<string,p>::iterator it = a.find(name1); map<string,p>::iterator itt = a.find(name2); if(it != a.end() && itt != a.end()) { if((it->second).password == password) { if((it->second).balance >= money) { (it->second).balance -= money; (itt->second).balance += money; cout<<"Successfully transfered money."<<endl; } else { cout<<"Money not enough."<<endl; } } else { cout<<"Wrong password."<<endl; } } else { cout<<"Account does not exist."<<endl; } } else if(c == 'C') { string name, password; cin>>name>>password; map<string,p>::iterator it = a.find(name); if(it != a.end()) { if((it->second).password == password) { cout<<(it->second).balance<<endl; } else { cout<<"Wrong password."<<endl; } } else { cout<<"Account does not exist."<<endl; } } else if(c == 'X') { string name, password1, password2; cin>>name>>password1>>password2; map<string,p>::iterator it = a.find(name); if(it != a.end()) { if((it->second).password == password1) { (it->second).password = password2; cout<<"Successfully changed password."<<endl; } else { cout<<"Wrong password."<<endl; } } else { cout<<"Account does not exist."<<endl; } } } }
另外,今天在帮胖胖和一宁查错的时候,学习了一个新插件,Notepad++的compare,直接在plugin安装那里选择最新的稳定的版本即可,查错十分方便。