2011年山东ACM第二届省赛 Mathman Bank(模拟)

8 篇文章 0 订阅

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


解:题目并不是很难,使用一连串的判断考研细心以及耐心。题意就是说模拟银行系统,银行开户,存款,取款,转账,查询余额,修改密码。根据输出中提示进行判断输出题目中要求输出文字即可。鉴于涉及字符串的输入与输出所以建议使用c++中输入输出流。


#include <iostream>
#include <cstring>
using namespace std;

struct Customer
{
    string name,password;
    long long account;
}customer[1005];
int n;
int find(string s)
{
    int i;
    for(i=0;i<n;++i)
        if(s==customer[i].name)
            return i;
    return -1;
}
void open()
{
    string nam,pas;
    long long acc;
    cin>>nam>>pas>>acc;
    if( find(nam)!=-1 )
    {
        cout<<"Account exists."<<endl;
        return;
    }
    customer[n].name=nam;
    customer[n].password=pas;
    customer[n].account=acc;
    n++;
    cout<<"Successfully opened an account."<<endl;
}
void deposite()
{
    string nam;
    long long acc;
    int x;
    cin>>nam>>acc;
    x=find(nam);
    if( x==-1 )
    {
        cout<<"Account does not exist."<<endl;
        return;
    }
    customer[x].account+=acc;
    cout<<"Successfully deposited money."<<endl;
}
void withdraw()
{
    string nam,pas;
    long long acc;
    int x;
    cin>>nam>>pas>>acc;
    x=find(nam);
    if(x==-1)
    {
        cout<<"Account does not exist."<<endl;
        return;
    }
    if( customer[x].password!=pas )
    {
        cout<<"Wrong password."<<endl;
        return;
    }
    if( customer[x].account<acc )
    {
        cout<<"Money not enough."<<endl;
        return;
    }
    customer[x].account-=acc;
    cout<<"Successfully withdrew money."<<endl;
}
void tranfer()
{
    string sender,receiver,pas;
    long long acc;
    int s1,r1;
    cin>>sender>>pas>>receiver>>acc;
    s1=find(sender);
    r1=find(receiver);
    if( s1==-1 || r1==-1 )
    {
        cout<<"Account does not exist."<<endl;
        return;
    }
    if( customer[s1].password!=pas )
    {
        cout<<"Wrong password."<<endl;
        return;
    }
    if( customer[s1].account<acc )
    {
        cout<<"Money not enough."<<endl;
        return;
    }
    customer[r1].account+=acc;
    customer[s1].account-=acc;
    cout<<"Successfully transfered money."<<endl;
}
void check()
{
    string nam,pas;
    int x;
    cin>>nam>>pas;
    x=find(nam);
    if( x==-1 )
    {
        cout<<"Account does not exist."<<endl;
        return;
    }
    if( customer[x].password!=pas )
    {
        cout<<"Wrong password."<<endl;
        return;
    }
    cout<<customer[x].account<<endl;
}
void chenge()
{
    string nam,oldpas,newpas;
    int x;
    cin>>nam>>oldpas>>newpas;
    x=find(nam);
    if( x==-1 )
    {
        cout<<"Account does not exist."<<endl;
        return;
    }
    if( customer[x].password!=oldpas )
    {
        cout<<"Wrong password."<<endl;
        return;
    }
    customer[x].password=newpas;
    cout<<"Successfully changed password."<<endl;
}

int main()
{
    int t;
    char c;
    cin>>t;
    n=0;
    while(t--)
    {
        cin>>c;
        switch(c)
        {
            case 'O':open();break;
            case 'D':deposite();break;
            case 'W':withdraw();break;
            case 'T':tranfer();break;
            case 'C':check();break;
            case 'X':chenge();break;
        }
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值