您的位置:首页 > 其它

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

2016-04-27 17:09 375 查看

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
.name=nam;
customer
.password=pas;
customer
.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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: