Leetcode—1410.HTML实体解析器【中等】

2023每日刷题(三十八)

Leetcode---1410.HTML实体解析器

算法思想

实现代码

python 复制代码
typedef struct entityChar {
    char* entity;
    char rechar;
}entity;

entity matches[] = {
    {""", '"'},
    {"'", '\''},
    {"&", '&'},
    {">", '>'},
    {"&lt;", '<'},
    {"&frasl;", '/'}
};

char* entityParser(char* text) {
    int n = strlen(text);
    char* ans = (char *)malloc(sizeof(char) * (n + 10));
    char* p = ans;
    int flag = 0;
    int i = 0;
    while(i < n) {
        flag = 0;
        if(text[i] == '&') {
            for(int j = 0; j < sizeof(matches) / sizeof(matches[0]); j++) {
                if(strncmp(text + i, matches[j].entity, strlen(matches[j].entity)) == 0) {
                    strcpy(p, &matches[j].rechar);
                    p += strlen(&matches[j].rechar);
                    i += strlen(matches[j].entity);
                    flag = 1;
                    break;
                }
            }
        }
        if(!flag) {
            *p = text[i];
            p++;
            i++;
        }
    }
    *p = '\0';
    return ans;
}

运行结果


之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!

相关推荐
LaughingZhu1 小时前
Product Hunt 每日热榜 | 2026-05-21
前端·人工智能·经验分享·chatgpt·html
moshi_63 小时前
“瀑布流“ 滚动网页采集工具
经验分享·网络爬虫·数据采集·网页抓取·瀑布流页面采集
心中有国也有家3 小时前
cann-recipes-infer:昇腾 NPU 推理的“菜谱集合”
经验分享·笔记·学习·算法
绝知此事3 小时前
【算法突围 01】线性结构与哈希表:后端开发的收纳术
java·数据结构·算法·面试·jdk·散列表
碧海银沙音频科技研究院3 小时前
通话AEC与语音识别AEC的软硬回采链路
深度学习·算法·语音识别
csdn_aspnet4 小时前
Python 算法快闪 LeetCode 编号 70 - 爬楼梯
python·算法·leetcode·职场和发展
LuminousCPP4 小时前
数据结构 - 线性表第四篇:C 语言通讯录优化升级全记录(踩坑 + 思考)
c语言·开发语言·数据结构·经验分享·笔记·学习
一只机电自动化菜鸟6 小时前
一建机电备考笔记(40) 建筑机电施工—排水管道施工(含考频+题型)
经验分享·笔记·学习·职场和发展·课程设计
m0_629494737 小时前
LeetCode 热题 100-----26.环形链表 II
数据结构·算法·leetcode·链表