[2011山东ACM省赛] Mathman Bank(模拟题)

2024-01-28 13:38

本文主要是介绍[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

提示

来源

山东省第二届ACM大学生程序设计竞赛

 

解题思路:

模拟银行开设账户,存款,取款,转账等业务,题目没难度,按照题意模拟,写代码时要仔细。

代码:

#include <iostream>
#include <string.h>
using namespace std;
struct Node//为每个账户开设一个结构体
{
string Name;//姓名
string Code;//密码
int Money;//存款金额
}node[1002];
int find(Node x[],int m,string name)//两个功能,判断name是否已经开了账户,如果已经开了返回在数组中的位置
{
for(int i=0;i<m;i++)
{
if(x[i].Name==name)
{
return i;
}
}
return -1;
}
int main()
{
int n;char cm;
int m=0;
cin>>n;
while(n--)
{
cin>>cm;
if(cm=='O')//开设账户
{
string name,code;
int money;
cin>>name>>code>>money;
if(find(node,m,name)==-1||m==0)//该姓名没有开账户
{
node[m].Name=name;
node[m].Code=code;
node[m].Money=money;
m++;
cout<<"Successfully opened an account."<<endl;
}
else
cout<<"Account exists."<<endl;
}
if(cm=='D')
{
string name;int money;
cin>>name>>money;
if(find(node,m,name)==-1)
cout<<"Account does not exist."<<endl;
else
{
node[find(node,m,name)].Money+=money;
cout<<"Successfully deposited money."<<endl;
}
}
if(cm=='W')
{
string name,code;int money;
cin>>name>>code>>money;
if(find(node,m,name)==-1)
{
cout<<"Account does not exist."<<endl;
}
else
{
if(node[find(node,m,name)].Code!=code)
{
cout<<"Wrong password."<<endl;
}
else if(node[find(node,m,name)].Money<money)
{
cout<<"Money not enough."<<endl;
}
else
{
node[find(node,m,name)].Money-=money;
cout<<"Successfully withdrew money."<<endl;
}
}
}
if(cm=='T')
{
string name1,code,name2;
int money;
cin>>name1>>code>>name2>>money;
if(find(node,m,name1)==-1||find(node,m,name2)==-1)
cout<<"Account does not exist."<<endl;
else if(node[find(node,m,name1)].Code!=code)
cout<<"Wrong password."<<endl;
else if(node[find(node,m,name1)].Money<money)
cout<<"Money not enough."<<endl;
else
{
node[find(node,m,name1)].Money-=money;
node[find(node,m,name2)].Money+=money;
cout<<"Successfully transfered money."<<endl;
}
}
if(cm=='C')
{
string name,code;
cin>>name>>code;
if(find(node,m,name)==-1)
{
cout<<"Account does not exist."<<endl;
}
else if(node[find(node,m,name)].Code!=code)
{
cout<<"Wrong password."<<endl;
}
else
{
cout<<node[find(node,m,name)].Money<<endl;
}
}
if(cm=='X')
{
string name,code1,code2;
cin>>name>>code1>>code2;
int len=find(node,m,name);
if(len==-1)
{
cout<<"Account does not exist."<<endl;
}
else if(node[len].Code!=code1)
{
cout<<"Wrong password."<<endl;
}
else
{
node[len].Code=code2;
cout<<"Successfully changed password."<<endl;
}
}
}
return 0;
}


 

 

这篇关于[2011山东ACM省赛] Mathman Bank(模拟题)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/653780

相关文章

认识、理解、分类——acm之搜索

普通搜索方法有两种:1、广度优先搜索;2、深度优先搜索; 更多搜索方法: 3、双向广度优先搜索; 4、启发式搜索(包括A*算法等); 搜索通常会用到的知识点:状态压缩(位压缩,利用hash思想压缩)。

机试算法模拟题 服务中心选址

题目描述 一个快递公司希望在一条街道建立新的服务中心。公司统计了该街道中所有区域在地图上的位置,并希望能够以此为依据为新的服务中心选址:使服务中心到所有区域的距离的总和最小。 给你一个数组positions,其中positions[i] = [left, right] 表示第 i 个区域在街道上的位置,其中left代表区域的左侧的起点,right代表区域的右侧终点,假设服务中心的位置为loca

【转载】ACM感悟

今天看了一篇我们学校前辈的ACM的感悟,觉得写的十分有道理,这里转载,文章还会不断的改进和更新。 原文链接:http://www.cnblogs.com/Chierush/p/3760870.html?ADUIN=1339764596&ADSESSION=1401536826&ADTAG=CLIENT.QQ.5329_.0&ADPUBNO=26349 声明:本文是写给弱校ACM新手的一点

我们依旧在追梦的路上-山东省第六届ACM比赛总结

这场比赛从结果而言达到了预期(金牌),从过程而言和我的预期相差甚远(打的太乱,个人发挥很差),还好关键时刻队友抗住压力,负责后果真的不堪设想。 热身赛 热身赛纯粹测机器的,先把A,B,C草草水过(A题小写x打成大写的也是醉了),我和老高开始各种测机器,long long不出所料是lld的,试了一下除0和数组越界的re问题,发现没有re,只有wa(甚至数组越界还AC了),至于栈深的话也没过多追

ACM东北地区程序设计大赛

不得不说随着参赛级别的提高,题目真的是越来越难啊,不过队长真是给力啊,在我们三个共同努力之下拿下了地区赛三等奖,哈哈我们可是大一唯一一只获奖队,终于在这次比赛打败了田大神。。。大神是失手了,俺和他差距还是挺大的。。。队友陈彤马上要去服兵役了,他说这是我们送给他最好的离别礼物,希望那家伙在部队好好干,以后谁干揍我!!!东北地区赛结束后,今年已经估计没机会参加亚洲区比赛了,赶紧补高数和线数啊!!别挂了

ACM比赛中如何加速c++的输入输出?如何使cin速度与scanf速度相当?什么是最快的输入输出方法?

在竞赛中,遇到大数据时,往往读文件成了程序运行速度的瓶颈,需要更快的读取方式。相信几乎所有的C++学习者都在cin机器缓慢的速度上栽过跟头,于是从此以后发誓不用cin读数据。还有人说Pascal的read语句的速度是C/C++中scanf比不上的,C++选手只能干着急。难道C++真的低Pascal一等吗?答案是不言而喻的。一个进阶的方法是把数据一下子读进来,然后再转化字符串,这种方法传说中

2014年ACM/ICPC亚洲区现场赛广州赛区总结

本来不想提这件事的,后来学姐找我谈心时提到这件事,我突然意识到在这件事情上我错了一次,明明答应的去参加这场比赛,最后临时决定不去......其实中间有很多很多原因 1:我和tyh,sxk临时不去主要是广州太远,我们身上money不够,呵呵。。。别笑我们,你以为我们是高富帅啊,去一趟广州消费要2个月的生活费,奖学金又没发,你让我找我妈要她辛辛苦苦挣来的工资吗?!从哈尔滨到广州单来回的火车票每个人就

找不同-第15届蓝桥省赛Scratch初级组真题第4题

[导读]:超平老师的《Scratch蓝桥杯真题解析100讲》已经全部完成,后续会不定期解读蓝桥杯真题,这是Scratch蓝桥杯真题解析第183讲。 如果想持续关注Scratch蓝桥真题解读,可以点击《Scratch蓝桥杯历年真题》并订阅合集,查阅教程更方便。 第15届蓝桥杯省赛已于2024年8月24日落下帷幕,编程题一共有5题,分别如下: 猪八戒落地 游乐场 画西瓜 找不同 消

【python】—— Python爬虫实战:爬取珠海市2011-2023年天气数据并保存为CSV文件

目录 目标 准备工作 爬取数据的开始时间和结束时间 爬取数据并解析 将数据转换为DataFrame并保存为CSV文件         本文将介绍如何使用Python编写一个简单的爬虫程序,以爬取珠海市2011年至2023年的天气数据,并将这些数据保存为CSV文件。我们将涉及到以下知识点: 使用requests库发送HTTP请求使用lxml库解析HTML文档使用dateti

第十五届蓝桥杯图形化省赛题目及解析

第十五届蓝桥杯图形化省赛题目及解析 一. 单选题 1. 运行以下程序,角色会说( )? A、29     B、31     C、33     D、35 正确答案:C 答案解析: 重复执行直到m>n不成立,即重复执行直到m<=n。所有当m小于或者 等于n时,循环结束。循环过程中变量m与变量n的变化如下表: 通过上述表格可知,循环到第五次循环结束。m的值为14,n的值为19