省赛2D题

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安装那里选择最新的稳定的版本即可,查错十分方便。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值