Mathman Bank(第二届ACM大学生程序设计竞赛 )

Problem Description
  With the development of mathmen's mathematics knowlege, they have finally  invented computers. Therefore, they want to use computers to manage their  banks. However, mathmen's programming skills are not as good as their  math- ematical skills. So they need your help to write a bank management  system software.

The system must support the following operations:

1. Open account: given the customer's name and password, and an initial deposit, open an bank account for the customer.

2. Deposit: given the amount of money and the name of the customer, deposit money in the customer's account.

3. Withdraw: given the amount of money, the customer's name and password, withdraw money from the customer's account.

4. Transfer: given the amount of money, sender's name, sender's password and receiver's name, transfer money from the sender's account to the

receiver's account.

5. Check: given the customer's name and password, print the balance of the customer's account.

6. Change password: given the customer's name and old password, and the new password, replace the customer's old password with the new one.

Initially, no account exists in the bank management system .

Input
  The first line of the input contains one positive integer, n (n <= 1000), which  is the number of commands.  Each of the following n lines contains one of the following commands, in  the following format:

1. O "customer" "password" "initial deposit" - open an account for "customer", set the password to "password" and deposit "inital deposit" money in the account. "customer" and "password" are strings, and "initial deposit" is an integer.

2. D "customer" "amount" - deposit "amount" money in "customer"'sac- count. "customer" is a string, and "amount" is an integer.

3. W"customer" "password" "amount" - withdraw "amount" money from "customer"'s account. "customer" and "password" are strings, and amount

4. T "sender" "password" "receiver" "amount" - transfer "amount" money from "sender"'s acount to "receiver"'s account. "sender", "pasword" and "receiver" are strings, and "amount" is an integer. 

5. C "customer" "password" - check "customer"'s balance. "customer" and "password" are strings.

6. X "customer" "old password" "new password" - replace "customer"'s old password with "new password". "customer", "old password" and "new password" are strings.

All of the strings appearing in the input consist of only alphebetical letters and digits, and has length at most 10. All the integers in the input are nonnegative, and at most 1000000.

Refer to the sample input for more details.

Output
For each of the commands, output one of the following results, respectively:

1. Open account: If "customer" already has an account, output "Account exists." (without quotation marks); otherwise, output "Successfully opened an account." (without quotation marks).

2. Deposite: If "customer" doesn't have an account ,output "Account does not exist."; otherwise, output "Successfully deposited money."(without quotation marks).

3. Withdraw: If "customer" doesn't have an account, output "Account does not exist."; otherwise, if "customer"'s password doesn't match "password", output "Wrong password."; otherwise, if there are less money than "amount" in "customer"'s account, output "Money not enough."; otherwise, output "Successfully withdrew money." quotation marks).

4. Transfer: If "sender"'s account or "receiver"'s account doesn't exist, output "Account does not exist."; otherwise, if "sender"'s password doesn't match "password", output "Wrong password."; otherwise, if there is less money than 'amount" in "sender"'s account, output "Money not enough."; otherwise, output "Successfully transfered money."

5. Check: If "customer"'s account doesn't exist, output "Account does not exist."; otherwise, if "customer"'s password doesn't match "password", output "Wrong password."; otherwise, output the balance of "customer"'s account.

6. Change password: If "customer" doesn't have an account, output "Account does not exist."; otherwise, if "customer"'s password doesn't match "old password", output "Wrong password."; otherwise, output 'Successfully changed password.".

Example Input
25
W Alice alice 10
O Alice alice 10
C Alice alice
D Bob 10000
O Bob bob 100
D Alice 50
C Alice alice
X Bob bob BOB
C Bob bob
O Bob bob 10
T Bob bob Alice 100000
W Alice alice 10
T Bob BOB Alice 100000
T Bob BOB Alice 100
C Alice alice
C Bob BOB
T Alice alice BOB 10
T ALICE alice Bob 10
X Jack jack JACE
X Alice ALICE alice
W Alice Alice 10
W Alice alice 200
T Alice alice Bob 80
C Alice alice
C Bob BOB
Example Output
Account does not exist.
Successfully opened an account.
10
Account does not exist.
Successfully opened an account.
Successfully deposited money.
60
Successfully changed password.
Wrong password.
Account exists.
Wrong password.
Successfully withdrew money.
Money not enough.
Successfully transfered money.
150
0
Account does not exist.
Account does not exist.
Account does not exist.
Wrong password.
Wrong password.
Money not enough.
Successfully transfered money.
70
80

纯模拟,实在是敲不出来,放上令神的代码,令神不愧是模拟大神。。。。

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define LL long long
#define INF 0x3f3f3f3f
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;

struct People
{
    string name;
    string pwd;
    int money;

    bool operator == (const People& t) const
    {
        return name == t.name;
    }
    bool operator < (const People& t) const
    {
        return this->name < t.name;
    }
};

vector<People> bank;

void open()
{
    string name, pwd;
    int money;
    cin >> name >> pwd >> money;
    People p = People {name,pwd,money};
    for(int i=0; i<bank.size(); ++i)
    {
        if(bank[i].name == name )
        {
            cout << "Account exists." << endl;
            return ;
        }
    }
    bank.push_back(p);
    cout << "Successfully opened an account." << endl;
}
void deposite()
{
    string name, pwd;
    int money;
    cin >> name >> money;
    for(int i=0; i<bank.size(); ++i)
    {
        if(bank[i].name == name)
        {
            bank[i].money += money;
            cout << "Successfully deposited money." << endl;
            return ;
        }

    }
    cout << "Account does not exist." << endl;
}
void withdraw()
{
    string name, pwd;
    int money;
    cin >> name >> pwd >> money;

    for(int i=0; i<bank.size(); ++i)
    {
        if(bank[i].name == name )
        {
            if(bank[i].pwd == pwd)
            {
                if(bank[i].money<money)
                {
                    cout << "Money not enough." << endl;
                }
                else
                {
                    bank[i].money -= money;
                    cout << "Successfully withdrew money." << endl;
                }
                return;
            }
            else
            {
                cout << "Wrong password." << endl;
                return ;
            }
        }
    }
    cout << "Account does not exist." << endl;
}

void transfer()
{
    string sname, pwd,rname;
    int money;
    cin >> sname >> pwd >>  rname >> money;
    People p ;
    p.name = "";
    int s = -1,r = -1;
    for(int i=0; i<bank.size(); ++i)
    {
        if(bank[i].name == sname) s = i;
        if(bank[i].name == rname) r = i;
    }

    if(s==-1 || r == -1)
    {
        cout << "Account does not exist." << endl;
    }
    else
    {
        if(pwd!=bank[s].pwd)
        {
            cout << "Wrong password." << endl;
        }
        else if(bank[s].money<money)
        {
            cout << "Money not enough." << endl;
        }
        else
        {
            bank[s].money -= money;
            bank[r].money += money;
            cout << "Successfully transfered money." << endl;
        }
    }
}

void check()
{
    string name, pwd;
    int money;
    cin >> name >> pwd;
    for(int i=0; i<bank.size(); ++i)
    {
        if(bank[i].name == name)
        {
            if(bank[i].pwd == pwd)
            {
                cout << bank[i].money << endl;
                return ;
            }
            else
            {
                cout << "Wrong password." << endl;
                return ;
            }
        }
    }
    cout << "Account does not exist." << endl;
}

void change()
{
    string name, pwd,npwd;
    int money;
    cin >> name >> pwd >> npwd;
    for(int i=0; i<bank.size(); ++i)
    {
        if(bank[i].name == name)
        {
            if(bank[i].pwd == pwd)
            {
                bank[i].pwd = npwd;
                cout << "Successfully changed password." << endl;
                return ;
            }
            else
            {
                cout << "Wrong password." << endl;
                return ;
            }
        }
    }
    cout << "Account does not exist." << endl;
}
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        char cmd[10];
        scanf("%s",cmd);
        if(cmd[0]=='O')
        {
            open();
        }
        else if(cmd[0]=='D')
        {
            deposite();
        }
        else if(cmd[0]=='W')
        {
            withdraw();
        }
        else if(cmd[0]=='T')
        {
            transfer();
        }
        else if(cmd[0]=='C')
        {
            check();
        }
        else if(cmd[0]=='X')
        {
            change();
        }
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 适合毕业设计、课程设计作业。这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。 所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值