SDUTOJ 2167 Mathman Bank 第二届ACM省赛题 模拟

2024-08-24 23:08

本文主要是介绍SDUTOJ 2167 Mathman Bank 第二届ACM省赛题 模拟,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

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大学生程序设计竞赛


题目看起来很长,但读起来不难,就是一个模拟银行的模拟题:


先前做的时候一直WA,一开四怀疑自己的链表有问题,用c++的vector类又写了一份,最后才找到错误的地方,原来自己还可以给自己转账。。。。。。。


C++代码一份:(STL中的string类,vector类)


#include <iostream>
#include <string>
#include <vector>using namespace std;struct node
{string name;string pswd;int mon;
};vector <node> ls;void O()
{string name,pswd;int ny;cin>>name>>pswd>>ny;vector <node> :: iterator it = ls.begin();while(it != ls.end()){if(it->name == name){cout<<"Account exists.\n";return ;}it++;}node t;t.name = name;t.pswd = pswd;t.mon = ny;ls.push_back(t);cout<<"Successfully opened an account."<<endl;
}void D()
{string name;int add;cin>>name>>add;vector <node> :: iterator it = ls.begin();while(it != ls.end()){if(it->name == name){it->mon += add;cout<<"Successfully deposited money."<<endl;return ;}it++;}cout<<"Account does not exist."<<endl;
}void W()
{string name,pswd;int sub;vector <node> :: iterator it = ls.begin();cin>>name>>pswd>>sub;while(it != ls.end()){if(it->name == name){if(it->pswd == pswd){if(it->mon >= sub){it->mon -= sub;cout<<"Successfully withdrew money."<<endl;}else{cout<<"Money not enough.\n";}}else{cout<<"Wrong password.\n";}return ;}it++;}cout<<"Account does not exist.\n";
}void T()
{string name,pswd,rename;int sub;vector <node> :: iterator it = ls.begin(),st = ls.end(),rt = ls.end();cin>>name>>pswd>>rename>>sub;while(it != ls.end()){if(it->name == name){st = it;}if(it->name == rename){rt = it;}if(st != ls.end() && rt != ls.end())break;it++;}if(st != ls.end() && rt != ls.end()){if(st->pswd == pswd){if(st->mon >= sub){st->mon -= sub;rt->mon += sub;cout<<"Successfully transfered money."<<endl;}else{cout<<"Money not enough.\n";}}else{cout<<"Wrong password."<<endl;}}else{cout<<"Account does not exist.\n";}
}void C()
{string name,pswd;vector <node> :: iterator it = ls.begin();cin>>name>>pswd;while(it != ls.end()){if(it->name == name){if(it->pswd == pswd){cout<<it->mon<<endl;}else{cout<<"Wrong password.\n";}return ;}it++;}cout<<"Account does not exist.\n";
}void X()
{string name,opswd,npswd;vector <node> :: iterator it = ls.begin();cin>>name>>opswd>>npswd;while(it != ls.end()){if(it->name == name){if(it->pswd == opswd){it->pswd = npswd;cout<<"Successfully changed password.\n";}else{cout<<"Wrong password.\n";}return ;}it++;}cout<<"Account does not exist.\n";
}int main()
{int t;string cm;ls.clear();cin>>t;while(t--){cin>>cm;if(cm[0] == 'O')O();else if(cm[0] == 'D')D();else if(cm[0] == 'W')W();else if(cm[0] == 'T')T();else if(cm[0] == 'C')C();else if(cm[0] == 'X')X();}return 0;
}


C语言链表代码一份:


#include <stdio.h>
#include <string.h>struct node
{char name[21];char pswd[21];int mon;node *next;
};void O(node *head)
{char name[21],pswd[21];int sr;scanf("%s%s%d",name,pswd,&sr);node *p = head;while(p->next){if(!strcmp(p->next->name,name)){printf("Account exists.\n");break;}p = p->next;}if(!p->next){node *r = new node;strcpy(r->name,name);strcpy(r->pswd,pswd);r->mon = sr;p->next = r;r->next = NULL;printf("Successfully opened an account.\n");}
}void D(node *head)
{char name[21];int sr;scanf("%s%d",name,&sr);node *p = head;while(p->next){if(!strcmp(name,p->next->name)){p->next->mon += sr;printf("Successfully deposited money.\n");break;}p = p->next;}if(!p->next){printf("Account does not exist.\n");}
}void W(node *head)
{char name[21],pswd[21];int sr;scanf("%s%s%d",name,pswd,&sr);node *p = head;while(p->next){if(!strcmp(p->next->name,name)){if(!strcmp(p->next->pswd,pswd)){if(sr <= p->next->mon){p->next->mon -= sr;printf("Successfully withdrew money.\n");}else{printf("Money not enough.\n");}}else{printf("Wrong password.\n");}break;}p = p->next;}if(!p->next){printf("Account does not exist.\n");}
}void T(node *head)
{char name[21],pswd[21],rename[21];int sr;scanf("%s%s%s%d",name,pswd,rename,&sr);node *p = head;node *q1 = NULL,*q2 = NULL;while(p->next){if(!strcmp(p->next->name,name))q1 = p->next;if(!strcmp(p->next->name,rename))q2 = p->next;if(q1 && q2)break;p = p->next;}if(q1 && q2){if(!strcmp(q1->pswd,pswd)){if(q1->mon >= sr){q1->mon -= sr;q2->mon += sr;printf("Successfully transfered money.\n");}else{printf("Money not enough.\n");}}elseprintf("Wrong password.\n");}else{printf("Account does not exist.\n");}}void C(node *head)
{char name[21],pswd[21];scanf("%s%s",name,pswd);node *p = head;while(p->next){if(!strcmp(p->next->name,name)){if(!strcmp(p->next->pswd,pswd)){printf("%d\n",p->next->mon);}else{printf("Wrong password.\n");}break;}p = p->next;}if(!p->next)printf("Account does not exist.\n");
}void X(node *head)
{char name[21],opswd[21],npswd[21];scanf("%s%s%s",name,opswd,npswd);node *p = head;while(p->next){if(!strcmp(p->next->name,name)){if(!strcmp(p->next->pswd,opswd)){strcpy(p->next->pswd,npswd);printf("Successfully changed password.\n");}else{printf("Wrong password.\n");}break;}p = p->next;}if(!p->next)printf("Account does not exist.\n");
}int main()
{node *head = new node;head->next = NULL;int t;char cm[11];scanf("%d",&t);while(t--){scanf("%s",cm);if(cm[0] == 'O')O(head);else if(cm[0] == 'D')D(head);else if(cm[0] == 'W')W(head);else if(cm[0] == 'T')T(head);else if(cm[0] == 'C')C(head);else if(cm[0] == 'X')X(head);}return 0;
}



这篇关于SDUTOJ 2167 Mathman Bank 第二届ACM省赛题 模拟的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

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

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

【C++】_list常用方法解析及模拟实现

相信自己的力量,只要对自己始终保持信心,尽自己最大努力去完成任何事,就算事情最终结果是失败了,努力了也不留遗憾。💓💓💓 目录   ✨说在前面 🍋知识点一:什么是list? •🌰1.list的定义 •🌰2.list的基本特性 •🌰3.常用接口介绍 🍋知识点二:list常用接口 •🌰1.默认成员函数 🔥构造函数(⭐) 🔥析构函数 •🌰2.list对象

usaco 1.2 Transformations(模拟)

我的做法就是一个一个情况枚举出来 注意计算公式: ( 变换后的矩阵记为C) 顺时针旋转90°:C[i] [j]=A[n-j-1] [i] (旋转180°和270° 可以多转几个九十度来推) 对称:C[i] [n-j-1]=A[i] [j] 代码有点长 。。。 /*ID: who jayLANG: C++TASK: transform*/#include<

hdu4431麻将模拟

给13张牌。问增加哪些牌可以胡牌。 胡牌有以下几种情况: 1、一个对子 + 4组 3个相同的牌或者顺子。 2、7个不同的对子。 3、13幺 贪心的思想: 对于某张牌>=3个,先减去3个相同,再组合顺子。 import java.io.BufferedInputStream;import java.io.BufferedReader;import java.io.IOExcepti

【每日一题】LeetCode 2181.合并零之间的节点(链表、模拟)

【每日一题】LeetCode 2181.合并零之间的节点(链表、模拟) 题目描述 给定一个链表,链表中的每个节点代表一个整数。链表中的整数由 0 分隔开,表示不同的区间。链表的开始和结束节点的值都为 0。任务是将每两个相邻的 0 之间的所有节点合并成一个节点,新节点的值为原区间内所有节点值的和。合并后,需要移除所有的 0,并返回修改后的链表头节点。 思路分析 初始化:创建一个虚拟头节点

每日一题|牛客竞赛|四舍五入|字符串+贪心+模拟

每日一题|四舍五入 四舍五入 心有猛虎,细嗅蔷薇。你好朋友,这里是锅巴的C\C++学习笔记,常言道,不积跬步无以至千里,希望有朝一日我们积累的滴水可以击穿顽石。 四舍五入 题目: 牛牛发明了一种新的四舍五入应用于整数,对个位四舍五入,规则如下 12345->12350 12399->12400 输入描述: 输入一个整数n(0<=n<=109 ) 输出描述: 输出一个整数

【算法专场】模拟(下)

目录 前言 38. 外观数列 算法分析 算法思路 算法代码 1419. 数青蛙 算法分析 算法思路 算法代码  2671. 频率跟踪器 算法分析 算法思路 算法代码 前言 在前面我们已经讲解了什么是模拟算法,这篇主要是讲解在leetcode上遇到的一些模拟题目~ 38. 外观数列 算法分析 这道题其实就是要将连续且相同的字符替换成字符重复的次数+

模拟实现vector中的常见接口

insert void insert(iterator pos, const T& x){if (_finish == _endofstorage){int n = pos - _start;size_t newcapacity = capacity() == 0 ? 2 : capacity() * 2;reserve(newcapacity);pos = _start + n;//防止迭代

PHP实现二叉树遍历(非递归方式,栈模拟实现)

二叉树定义是这样的:一棵非空的二叉树由根结点及左、右子树这三个基本部分组成,根据节点的访问位置不同有三种遍历方式: ① NLR:前序遍历(PreorderTraversal亦称(先序遍历)) ——访问结点的操作发生在遍历其左右子树之前。 ② LNR:中序遍历(InorderTraversal) ——访问结点的操作发生在遍历其左右子树之中(间)。 ③ LRN:后序遍历(PostorderT

参会邀请 | 第二届机器视觉、图像处理与影像技术国际会议(MVIPIT 2024)

第二届机器视觉、图像处理与影像技术国际会议(MVIPIT 2024)将于2024年9月13日-15日在中国张家口召开。 MVIPIT 2024聚焦机器视觉、图像处理与影像技术,旨在为专家、学者和研究人员提供一个国际平台,分享研究成果,讨论问题和挑战,探索前沿技术。诚邀高校、科研院所、企业等有关方面的专家学者参加会议。 9月13日(周五):签到日 9月14日(周六):会议日 9月15日(周日