网易笔试 网易秋招 网易笔试题 1012

笔试时间:2025年10月12日

往年笔试合集:

2023春招秋招笔试合集

2024春招秋招笔试合集

第一题:简单模板引擎校验

假设需要设计一个模板渲染引擎,给定一个字符串,判断该输入的模板字符串是否合法有效。模板引擎采用双花括号匹配方式,用于替换中间的变量。

有效字符串需满足:

  1. 必须采用相邻双花括号方式进行匹配,并且要求是闭合的,例如 {{a}} 合法, {a} 不合法
  2. 双花括号之间必须有有效字符,不可以只包含空格,例如 {{ }} 不合法
  3. 在双花括号之间存在有效字符的情况下,允许存在空格,例如 {{ a }} 合法
  4. 允许出现多个模板匹配,但不允许嵌套,例如 {{a}} {{b}} 合法, {{{a}} b}} 不合法, {{a {{b}}}} 不合法

备注:

  • 每次仅仅输入一个模板字符串
  • 如果不包含任何双花括号,认定为有效模板

输入描述

输入为需要判断有效性的字符串模板

输出描述

输出是否为有效字符串,布尔值,有效返回 true,无效返回 false

样例输入

this is a {{question}}

样例输出

true

双花括号匹配,符合要求。

参考题解

解题思路:

  1. 逐个字符遍历输入字符串
  2. 寻找起始标记{{,如果找到单个{则判定无效
  3. 找到{{后继续查找对应的}},期间检查是否有嵌套
  4. 提取双花括号之间的内容,检查是否包含至少一个非空格字符
  5. 处理不成对的括号情况

C++:

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

bool isValidTemplate(string template_str) {
    int strLen = template_str.length();
    int index = 0;
    
    while (index < strLen) {
        if (template_str[index] == '{') {
            if (index + 1 >= strLen || template_str[index + 1] != '{') {
                return false;
            }
            index += 2;
            int contentStartIdx = index;
            bool foundClosingBrackets = false;
            
            while (index < strLen - 1) {
                if (template_str[index] == '{' && template_str[index + 1] == '{') {
                    return false;
                }
                if (template_str[index] == '}' && template_str[index + 1] == '}') {
                    int contentEndIdx = index - 1;
                    bool hasNonSpaceChar = false;
                    for (int contentIdx = contentStartIdx; contentIdx <= contentEndIdx; contentIdx++) {
                        if (template_str[contentIdx] != ' ') {
                            hasNonSpaceChar = true;
                            break;
                        }
                    }
                    if (!hasNonSpaceChar) {
                        return false;
                    }
                    index += 2;
                    foundClosingBrackets = true;
                    break;
                }
                index++;
            }
            if (!foundClosingBrackets) {
                return false;
            }
        } else if (template_str[index] == '}') {
            return false;
        } else {
            index++;
        }
    }
    return true;
}

int main() {
    string templateStr;
    getline(cin, templateStr);
    cout << (isValidTemplate(templateStr) ? "true" : "false") << endl;
    return 0;
}

Java:

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String templateStr = scanner.nextLine();
        System.out.println(isValidTemplate(templateStr));
        scanner.close();
    }
    
    private static boolean isValidTemplate(String template) {
        int strLen = template.length();
        int index = 0;
        
        while (index < strLen) {
            if (template.charAt(index) == '{') {
                if (index + 1 >= strLen || template.charAt(index + 1) != '{') {
                    return false;
                }
                index += 2;
                int contentStartIdx = index;
                boolean foundClosingBrackets = false;
                
                while (index < strLen - 1) {
                    if (template.charAt(index) == '{' && template.charAt(index + 1) == '{') {
                        return false;
                    }
                    if (template.charAt(index) == '}' && template.charAt(index + 1) == '}') {
                        int contentEndIdx = index - 1;
                        boolean hasNonSpaceChar = false;
                        for (int contentIdx = contentStartIdx; contentIdx <= contentEndIdx; contentIdx++) {
                            if (template.charAt(contentIdx) != ' ') {
                                hasNonSpaceChar = true;
                                break;
                            }
                        }
                        if (!hasNonSpaceChar) {
                            return false;
                        }
                        index += 2;
                        foundClosingBrackets = true;
                        break;
                    }
                    index++;
                }
                if (!foundClosingBrackets) {
                    return false;
                }
            } else if (template.charAt(index) == '}') {
                return false;
            } else {
                index++;
            }
        }
        return true;
    }
}

Python:

def is_valid_template(template):
    str_len = len(template)
    index = 0
    
    while index < str_len:
        if template[index] == '{':
            if index + 1 >= str_len or template[index + 1] != '{':
                return False
            index += 2
            content_start_idx = index
            found_closing_brackets = False
            
            while index < str_len - 1:
                if template[index] == '{' and template[index + 1] == '{':
                    return False
                if template[index] == '}' and template[index + 1] == '}':
                    content_end_idx = index - 1
                    has_non_space_char = False
                    for content_idx in range(content_start_idx, content_end_idx + 1):
                        if template[content_idx] != ' ':
                            has_non_space_char = True
                            break
                    if not has_non_space_char:
                        return False
                    index += 2
                    found_closing_brackets = True
                    break
                index += 1
            
            if not found_closing_brackets:
                return False
        elif template[index] == '}':
            return False
        else:
            index += 1
    
    return True

template_str = input()
print("true" if is_valid_template(template_str) else "false")

第二题:最长公共子序列

给定两个字符串 s1 和 s2,返回这两个字符串的最长公共子序列的长度。如果不存在公共子序列,返回 0。

一个字符串的子序列是指这样一个新的字符串:它是由原字符串在不改变字符的相对顺序的情况下删除某些字符(也可以不删除任何字符)后组成的新字符串。

输入描述

两个字符串,s1 和 s2

输出描述

返回这两个字符串的最长公共子序列的长度

样例输入

abcde

ace

样例输出

3

参考题解

解题思路:使用动态规划解决:

  1. 定义状态:dp[i][j]表示字符串s1的前i个字符和字符串s2的前j个字符的最长公共子序列长度
  2. 状态转移: 如果s1[i-1] == s2[j-1],则dp[i][j] = dp[i-1][j-1] + 1否则,dp[i][j] = max(dp[i-1][j], dp[i][j-1])

C++:

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    string text1, text2;
    

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

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

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

全部评论
a了3.6,第一题就a了0.9忘记cpp怎么输入带空格字符串了
点赞 回复 分享
发布于 10-13 08:25 黑龙江

相关推荐

高校就业办老师揭秘,3分钟让你的简历起死回生!同学们,我是奔波在各大高校招聘会多年的就业指导老师。每年秋招,我最痛心的就是看到许多同学能力很强,却败在了一份糟糕的简历上。今天,我要揭露HR看到就直接拒绝的6种简历,并教你如何用3分钟让你的简历“起死回生”!一、HR秒拒的6种简历,第一条就踩雷!根据多家企业HR的反馈,以下六种简历在筛选中淘汰率高达90%:1.&nbsp;简历附带超长求职信&nbsp;-&nbsp;HR通常在15-30秒内浏览一份简历,求职信过长会直接导致被拒。2.&nbsp;简历不完整&nbsp;-&nbsp;工作经验缺失或时间空白,会让HR怀疑你的求职态度和诚信度。3.&nbsp;简历表述过简&nbsp;-&nbsp;工作经历只写到年份,教育情况只写“大专”或“大本”,信息有限让HR无法判断你的能力。4.&nbsp;简历出现明显错误&nbsp;-&nbsp;时间错误如“上十几年的大专”,或教育经历与工作经历完全重叠,会被立刻抛弃。5.&nbsp;简历附件形式或标题不明确&nbsp;-&nbsp;邮件只写“应聘”或“个人简历”,会被HR放在最后浏览,很可能永远没机会被看到。6.&nbsp;用怪异的邮箱名发送简历&nbsp;-&nbsp;如“没油了”、“彻夜跳舞”等,会被HR果断抛弃。二、简历四大核心错误,八成求职者都犯过除了上述问题,根据中国公共招聘网的专业指导,简历还有四个常见核心错误:7.&nbsp;缺乏重点:一份简历看上去适合任何职位,实际上适合&nbsp;none。你必须明确能干什么、优势在哪里、谋求什么职位。8.&nbsp;缺少营销战略:求职本质是推销自己!你的简历应该是份销售书,目的是进入面试。9.&nbsp;没有业绩陈述:过去的工作成绩是雇主评判你未来表现的依据。业绩必须量化:节省了多少成本?提高了多少效率?增加了多少收入?10.&nbsp;格式不当:简历格式有三种——时间型、功能型和混合型。选择合适的格式至关重要。三、黄金简历制作法:3分钟让你的简历起死回生第1分钟:选择合适格式-&nbsp;同一行业同一工种:用时间型简历-&nbsp;换行业或岗位:用功能型简历,突出可迁移技能-&nbsp;最有优势:混合型简历,既展示成长路径,又突出核心能力第2分钟:量化工作业绩这是让HR眼前一亮的最关键一步!看两个例子:修改前:“负责社交媒体运营,增加粉丝数量”修改后:“3个月内通过精准内容策略,使微博粉丝从1万增长至5万,增长率为400%”修改前:“参与公司成本控制项目”修改后:“提出并实施办公用品集中采购方案,年节省成本约12万元”第3分钟:针对性修改切忌一份简历投遍所有公司!针对不同岗位调整重点,确保你的核心能力与岗位要求完美匹配。四、简历救星来了,免费好用不花钱!看到这里,你可能已经发现自己简历中的问题了。别急,我和团队开发的AiCV简历王小程序就是来拯救你的!这款小程序之所以被称为“简历救星”,因为它能帮你:-&nbsp;一键诊断:AI智能分析简历问题,指出潜在雷区-&nbsp;智能优化:一键重构简历表述,让平淡经历变亮眼-&nbsp;量化成果:自动提示添加数据支撑,增强说服力-&nbsp;岗位匹配:根据目标岗位智能调整关键词,提高通过率-&nbsp;模板海量:提供各行业HR认可的專業模板最重要的是,这么强大的工具,完全免费!不会让你掏一分钱。要使用的朋友们可以在常用绿色泡泡小程序里搜索“AiCV简历王小程序”工具是免费的,但你的时间和机会是无价的。祝愿每一位努力的同学,都能得偿所愿,拿到心仪的Offer。
读研or工作,哪个性价比...
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

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