SDUT 2167 Mathman Bank 模拟

本文介绍了一个简单的银行系统模拟程序,该程序使用 C++ 实现,能够处理账户开立、存款、取款、转账及查询等功能,并通过案例演示了各种操作的具体实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题意:

大模拟,模拟银行操作。

分析:

按题意一个一个操作的进行就好了

ACcode:

#include <bits/stdc++.h>
#include <string>
#define maxn 1000005
#define ll long long
using namespace std;
map<string,int>vis;
struct N{
    string id,ps;
    ll v;
    void init(){///不初始化会发生错误
        id="";
        ps="";
        v=0;
    }
}my[maxn];
char s[100];
string t1,t2,t3;
int main(){
    int n,tot;
    ll add;
    while(scanf("%d",&n)!=EOF){
        vis.clear();
        for(int i=0;i<maxn;++i)my[i].init();
        tot=1;
        for(int i=0;i<n;++i){
            scanf("%s",s);
            switch(s[0]){
                case 'O':{
                    cin>>t1>>t2>>add;
                    if(vis[t1])puts("Account exists.");
                    else {
                        vis[t1]=tot;
                        my[tot].id=t1;
                        my[tot].ps=t2;
                        my[tot].v=add;
                        tot++;
                        puts("Successfully opened an account.");
                    }
                    break;
                }
                case 'D':{
                    cin>>t1>>add;
                    if(vis[t1]){
                        my[vis[t1]].v+=add;;
                        puts("Successfully deposited money.");
                    }
                    else puts("Account does not exist.");
                    break;
                }
                case 'W':{
                    cin>>t1>>t2>>add;
                    if(vis[t1]){
                        int pos=vis[t1];
                        if(t2!=my[pos].ps)puts("Wrong password.");
                        else {
                            if(my[pos].v<add)puts("Money not enough.");
                            else {
                                my[pos].v-=add;
                                puts("Successfully withdrew money.");
                            }
                        }
                    }
                    else puts("Account does not exist.");
                    break;
                }
                case 'T':{
                    cin>>t1>>t2>>t3>>add;
                    if(vis[t1]==0||vis[t3]==0)puts("Account does not exist.");
                    else {
                        int pos1=vis[t1],pos2=vis[t3];
                        if(my[pos1].ps!=t2)puts("Wrong password.");
                        else {
                            if(my[pos1].v<add)puts("Money not enough.");
                            else {
                                my[pos1].v-=add;
                                my[pos2].v+=add;
                                puts("Successfully transfered money.");
                            }
                        }
                    }
                    break;
                }
                case 'C':{
                    cin>>t1>>t2;
                    if(vis[t1]){
                        int pos=vis[t1];
                        if(my[pos].ps!=t2)puts("Wrong password.");
                        else cout<<my[pos].v<<'\12';
                    }
                    else puts("Account does not exist.");
                    break;
                }
                case 'X':{
                    cin>>t1>>t2>>t3;
                    if(vis[t1]){
                        int pos=vis[t1];
                        if(my[pos].ps==t2){
                            my[pos].ps=t3;
                            puts("Successfully changed password.");
                        }
                        else puts("Wrong password.");
                    }
                    else puts("Account does not exist.");
                    break;
                }
            }
        }
        cout<<'\12';
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值