民生银行笔试 民生银行笔试题 0508

笔试时间:2025年5月8日

往年笔试合集:

2023春招秋招笔试合集

2024春招秋招笔试合集

第一题

给定一个字符串s,请判断其是否为合法的括号序列。字符串中可能包含三种括号:‘(’与')’、'{’与'}’、‘[’与‘]’,也可能包含其他非括号字符。 如果忽略非括号字符后,在剩余的序中插入字符+和1就可以得到正确的算术表达式,那么这个括号序列就称为合法的括号序列。例如,""、"(())" 和"()()" 是合法的括号序列,因为填入内容后可以表示为"1"、"((1))"和"(1)+(1)"更严格地,一个括号序列被称为合法的括号序列,当且仅当每个左括号都能与某一对应的右括号--配对: 1.空串是合法的括号序列; 2.如果 A 是合法的括号序列,那么 "(A)"、"{A}""[A]"也是合法的括号序列; 3.如果 A 和 B 都是合法的括号序列,那么 AB 也是合法的括号序列。

输入描述

在一行上输入一个长度为1 ≤ len(s) ≤ 10^3,由六种括号和和其他可打印字符组成的字符串 s。

输出描述

如果字符串s是合法的括号序列,则输出 YES,否则输出 NO。

样例输入

{[(])}

样例输出

NO

参考题解

模拟

C++:

#include <iostream>
#include <cmath>
#include <string>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    cin.ignore(); // 忽略换行符

    string prevC1, prevC2;
    double prevR = 0.0;

    for (int i = 0; i < n; i++) {
        int a, b;
        double r;
        string c1, c2;

        cin >> a >> b >> c1 >> c2 >> r;
        cin.ignore(); // 忽略换行符

        // 是否被拒绝
        if (a * r < b) {
            cout << "REJECTED" << endl;
            continue;
        }

        // 第一笔通过
        if (i == 0) {
            cout << "APPROVED" << endl;
            prevC1 = c1;
            prevC2 = c2;
            prevR = r;
            continue;
        }

        // 计算汇率波动率
        double prevRate;
        bool sameDirection = (c1 == prevC1 && c2 == prevC2);
        if (sameDirection) {
            prevRate = prevR;
        } else {
            prevRate = 1.0 / prevR;
        }

        double fluctuation = ((r - prevRate) / prevRate) * 100;
        double absFluctuation = abs(fluctuation);

        if (absFluctuation > m) {
            cout << "REVIEW" << endl;
        } else {
            cout << "APPROVED" << endl;
        }

        // 更新上一笔信息
        prevC1 = c1;
        prevC2 = c2;
        prevR = r;
    }

    return 0;
}

Java:

import java.util.*;

publicclass Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        Map<Character, Character> map = new HashMap<>();
        map.put(')', '(');
        map.put('}', '{');
        map.put(']', '[');
        Stack<Character> stack = new Stack<>();
        
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (ch == '(' || ch == '{' || ch == '[') {
                stack.push(ch);
            } elseif (ch == ')' || ch == '}' || ch == ']') {
                if (stack.isEmpty()) {
                    System.out.println("NO");
                    return;
                }
                char top = stack.pop();
                if (top != map.get(ch)) {
                    System.out.println("NO");
                    return;
                }
            }
        }
        
        System.out.println(stack.isEmpty() ? "YES" : "NO");
    }
}

Python:

def main():
    n, m = map(int, input().split())
    prev_c1, prev_c2 = None, None
    prev_r = 0.0

    for i in range(n):
        a, b, c1, c2, r = input().split()
        a, b, r = int(a), int(b), float(r)

        # 是否被拒绝
        if a * r < b:
            print("REJECTED")
            continue

        # 第一笔通过
        if i == 0:
            print("APPROVED")
            prev_c1, prev_c2 = c1, c2
            prev_r = r
            continue

        # 计算汇率波动率
        if c1 == prev_c1 and c2 == prev_c2:
            prev_rate = prev_r
        else:
            prev_rate = 1.0 / prev_r

        fluctuation = ((r - prev_rate) / prev_rate) * 100
        abs_fluctuation = abs(fluctuation)

        if abs_fluctuation > m:
            print("REVIEW")
        else:
            print("APPROVED")

        # 更新上一笔信息
        prev_c1, prev_c2 = c1, c2
        prev_r = r

if __name__ == "__main__":
    main()

第二题

现在有以下王张表:客户表Customer(Customerld,CustomerName,CustomerGender)CustomerGender码值: Male,Female 产品表Product(ProductldProductName, ProductType)ProductType码值:DEPOS下存款类、LOAN-贷款类 交易表Transaction(Transactionld,Customerld, Productld,Amount)使用MySQL数据库,按要求写出SQL语句 求所有女性客户的贷款类产品平均交易金额,输出产品名#称及平均交易金额,按平均交易金额降序排列。

输入描述

drop table if exists Product;CREATE TABLE Product (ProductId INT PRIMARY KEY,ProductName VARCHAR(100) NOT NULL,ProductType ENUM('DEPOS', 'LOAN') NOT NULL
INSERT INTO Product (Productld, ProductName, ProductType) VALUES
(1,'定期存款,'DEPOS'),
(2,'活期存款,DEPOS'),
(3,个人贷款,LOAN'),
(4,'房贷,LOAN'),
(5,'汽车贷款,LOAN');
drop table if exists Customer;
CREATE TABLE Customer (Customerld INT PRIMARY KEY,CustomerName VARCHAR(1

剩余60%内容,订阅专栏后可继续查看/也可单篇购买

2025 春招笔试合集 文章被收录于专栏

2025打怪升级记录,大厂笔试合集 C++, Java, Python等多种语言做法集合指南

全部评论

相关推荐

不愿透露姓名的神秘牛友
10-22 11:56
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务