[2011山东省第二届ACM大学生程序设计竞赛]——Mathman Bank

Mathman Bank

Time Limit: 1000MS Memory limit: 65536K

题目描述

  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 .

输入

  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.

输出

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.".

示例输入

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

示例输出

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


这道题也是模拟题,属于模拟题中题目不难想,考验细节处理能力的。

这种类型,细心即可,一点都不难。

根据输入的第一个字符跳转到不同函数:

每个函数输入数据还不一样。

要注意以下判断:

①基本上都需要判断账户是否存在。(尤其转账,不止要判断寄钱人账户存在性,也要判断收钱人账户存在否)

②需要转账、取款等都需要判断密码是否正确

③进行转账,取钱等判断余额是否足够。

这些都要按照我上述给的顺序,

千万不要先判断余额是否足够再判断密码是否正确

最后,每次操作都会有输出语句。

样例中每种语句都出现了,基本把样例过了,就会AC了= =。


#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <string.h>
using namespace std;

struct Customer
{
    string name,password;
    long long account;
}cus[1010];
int total;

// 查找账户,如果不存在返回-1,存在则返回位置
int find_zh(string s)
{
    int i;
    for(i=0;i<total;++i)
        if(s==cus[i].name)
            return i;
    return -1;
}

// 转换到相应操作

// 开户
void turn_o(void)
{
    string nme,pwd;
    long long act;
    cin>>nme>>pwd>>act;
    // 判断账户是否已经存在
    if( find_zh(nme)!=-1 )
    {
        cout<<"Account exists."<<endl;
        return;
    }
    // 开户操作
    cus[total].name=nme;
    cus[total].password=pwd;
    cus[total].account=act;
    ++total;
    cout<<"Successfully opened an account."<<endl;
    return;
}
// 存款
void turn_d(void)
{
    string nme;
    long long act;
    int xh;
    cin>>nme>>act;
    xh=find_zh(nme);
    // 账户是否存在
    if( xh==-1 )
    {
        cout<<"Account does not exist."<<endl;
        return;
    }
    // 进行存款
    cus[xh].account+=act;
    cout<<"Successfully deposited money."<<endl;
    return;
}
// 取款
void turn_w(void)
{
    string nme,pwd;
    long long act;
    int xh;
    cin>>nme>>pwd>>act;
    // 账户是否存在
    xh=find_zh(nme);
    if(xh==-1)
    {
        cout<<"Account does not exist."<<endl;
        return;
    }
    // 密码是否正确
    if( cus[xh].password!=pwd )
    {
        cout<<"Wrong password."<<endl;
        return;
    }
    // 账户存在,判断余额是否足够
    if( cus[xh].account<act )
    {
        cout<<"Money not enough."<<endl;
        return;
    }
    // 进行取款
    cus[xh].account-=act;
    cout<<"Successfully withdrew money."<<endl;
    return;
}
// 转账
void turn_t(void)
{
    string sender,receiver,pwd;
    long long act;
    int s1,r1;
    cin>>sender>>pwd>>receiver>>act;
    s1=find_zh(sender);
    r1=find_zh(receiver);
    // 寄钱或者收钱的账户都要存在
    if( s1==-1 || r1==-1 )
    {
        cout<<"Account does not exist."<<endl;
        return;
    }
    // 密码是否正确
    if( cus[s1].password!=pwd )
    {
        cout<<"Wrong password."<<endl;
        return;
    }
    // 寄钱的账户余额是否足够
    if( cus[s1].account<act )
    {
        cout<<"Money not enough."<<endl;
        return;
    }
    // 进行转账
    cus[r1].account+=act;
    cus[s1].account-=act;
    cout<<"Successfully transfered money."<<endl;
    return;
}
// 查询
void turn_c(void)
{
    string nme,pwd;
    int xh;
    cin>>nme>>pwd;
    xh=find_zh(nme);
    if( xh==-1 )
    {
        cout<<"Account does not exist."<<endl;
        return;
    }
    // 密码是否正确
    if( cus[xh].password!=pwd )
    {
        cout<<"Wrong password."<<endl;
        return;
    }
    // 进行查询
    cout<<cus[xh].account<<endl;
    return;
}
// 改密码
void turn_x(void)
{
    string nme,old_pwd,new_pwd;
    int xh;
    cin>>nme>>old_pwd>>new_pwd;
    xh=find_zh(nme);
    if( xh==-1 )
    {
        cout<<"Account does not exist."<<endl;
        return;
    }
    if( cus[xh].password!=old_pwd )
    {
        cout<<"Wrong password."<<endl;
        return;
    }
    // 改密码操作
    cus[xh].password=new_pwd;
    cout<<"Successfully changed password."<<endl;
    return;
}

int main()
{
    int n;
    char c;
    cin>>n;
    total=0;
    while(n--)
    {
        cin>>c;
        switch(c)
        {
            case 'O':turn_o();break;
            case 'D':turn_d();break;
            case 'W':turn_w();break;
            case 'T':turn_t();break;
            case 'C':turn_c();break;
            case 'X':turn_x();break;
        }
    }
    return 0;
}




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值