HDU1867 A + B for you again KMP应用

实战:RK3568 Android14 调试 ES8388 音频驱动 (MIC 篇) 这个板子的MIC设计使用了硬件自动切换方案,极大简化了软件层面的逻辑。我们不需要根据耳机插拔事件去编写复杂的路由切换代码,只需要守住 LIN1/RIN1 这一个入口,配置好增益,剩下的交给那颗 SGM3157 芯片即可。祝您的录音功能调试顺利! 阅读详情

Problem Description

Generally speaking, there are a lot of problems about strings processing. Now you encounter another such problem. If you get two strings, such as “asdf” and “sdfg”, the result of the addition between them is “asdfg”, for “sdf” is the tail substring of “asdf” and the head substring of the “sdfg” . However, the result comes as “asdfghjk”, when you have to add “asdf” and “ghjk” and guarantee the shortest string first, then the minimum lexicographic second, the same rules for other additions.

Input

For each case, there are two strings (the chars selected just form ‘a’ to ‘z’) for you, and each length of theirs won’t exceed 10^5 and won’t be empty.

Output

Print the ultimate string by the book.

Sample Input

asdf sdfg
asdf ghjk

Sample Output

asdfg
asdfghjk

解题思路

对两个字符串分别KMP,得到相同前后缀长度。再根据长度判断该如何输出

#include <cstdio>
#include <cstring>
const int maxn = 100010;
int next[maxn];
char s1[maxn],s2[maxn];
int len1,len2;
void get_next(char *a)
{
    int len = strlen(a);
    int k = -1;
    int j = 0;
    next[j] = k;
    while(a[j] != '\0') {
        if(k == -1 || a[j] == a[k]) {
            k++;j++;
            next[j] = k;
        }else k = next[k];
    }
}
int kmp(char *a,char *b)
{ //a主串 b模式串
    get_next(b);
    int i = 0,j = 0;
    while(a[i] != '\0') {
        if(j == -1 || a[i] == b[j]) {
            i++;j++;
        }else j = next[j];
    }
    return j;
}
int main()
{
    while(scanf("%s%s",s1,s2) != EOF) {
        len1 = strlen(s1);
        len2 = strlen(s2);
        int str1 = kmp(s1,s2);
        int str2 = kmp(s2,s1);
        if(str1 == str2) {
            if(strcmp(s1,s2) < 0) printf("%s%s\n",s1,s2+str1);
            else printf("%s%s\n",s2,s1+str1);
        }else if(str1 < str2) {
            printf("%s%s\n",s2,s1+str2);
        }else printf("%s%s\n",s1,s2+str1);
    }
    return 0;
}
Linux C/C++ or 嵌入式面试之《C/C++笔面试系列》(10) C++ 前置后置增减运算符重载形式与比较 C语言的++、–运算符在此不讨论。 文章目录1、前置后置增减运算符重载的形式2、前置和后置运算符的性能比较 1、前置后置增减运算符重载的形式 自增运算符“++”和自减运算符“–”分别包含两个版本。即运算符前置形式(如 ++x)和运算符后置形式(如 x++),这两者进行的操作是不一样的。因此,当我们在对这两个运算符进行重载时,就必须区分前置和后置形式。C++根据参数的个数来区分前置和后置形式。如果按照通常的方法来重载 ++ 运算符(即作为成员函数重载时不带参数,或者作为非成员函数重载时带有一个参数),那么重载 阅读详情

相关推荐

别再为reg2icg的setup违例头疼了!手把手教你用ICC2/Innovus这3招搞定(附实战数据对比)

本文详细介绍了在ICC2/Innovus中解决reg2icg的setup违例的三种高效方法,包括早期时钟树预估、精准控制时钟延迟与门控检查以及ICG专用优化选项组合。通过实战数据对比,展示了不同策略的效果差异,帮助工程师快速优化时序路径,提升芯片性能。

weixin_42569329的博客 412

hdu A + B for you again

A + B for you again Time Limit : 5000/1000ms (Java/Other)Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 3Accepted Submission(s) : 1 Problem Description Generally speaking, th...

weixin_30633405的博客 190

深入浅出DDR系列(二)--DDR工作原理

学习完了DDR的基本组成和硬件结构原理之后,从整体上了解了DDR的特性和静态图,包括原理、管脚图等。那么本章就要从动态的角度来分析时序结构,包括read/write的整个过程到数据返回发生了什么,其中包括以下内容 DDR是如何完成Read、Write 等的操作 DDR的基本命令 DDR的时序参数 DDR的性能分析 1. DRAM基本组成 对于DRAM,其主要由行和列组成,每一个bit中都是由类似右下图的类晶体管的结构组成,对于sdram的数据,可以通过控制column和row就可以访问sd

奇小葩 3万+

HDU1867:A + B for you again

Problem Description Generally speaking, there are a lot of problems about strings processing. Now you encounter another such problem. If you get two strings, such as “asdf” and “sdfg”, the result of

ACM!荣耀之路! 2382

基于 SquashFS 构建 Linux 可读写文件系统

嵌入式 Linux 启动过程 本文所描述的的 Linux Image 由 BootLoader、kernel、initrd、rootfs 组成,它们共同存在于一个可以启动的存储设备中(本文以 USB 为例)。组成架构如下: 图 1. 可启动 linux 镜像文件结构 各个模块的作用如下: Boot Loader:由 BIOS 加载,用于将后续的 Kernel 和 initrd 的装载到内存中 kernel:为 initrd 运行提供基础的运行环境 initrd:检测并加载各种驱动程序 ro

wzq2009的专栏 1175

【异常】Cursor 编辑器 “Too many computers“ 报错排查与完整解决方案

该报错通常在启动Cursor、调用AI对话/代码补全核心功能时触发,会直接阻断编辑器AI能力的正常使用。

奶爸的编程之路,也就一周冷个三天 478

D - A + B for you again

Generally speaking, there are a lot of problems about strings processing. Now you encounter another such problem. If you get two strings, such as “asdf” and “sdfg”, the result of the addition between

ACM77的博客 903

webrtc进阶-- FlexFEC 实现原理与调试分析(m80 代码对齐版)

WebRTC 中 FlexFEC 技术解析与调试指南 摘要:本文深入分析 WebRTC 的 FlexFEC(灵活前向纠错)技术实现原理,重点探讨其在 m80 版本中的协商机制、接收侧恢复流程以及 SFU 场景下的特殊处理。文章指出 FlexFEC 通过动态冗余策略提升弱网抗丢包能力,详细解析了编解码器分配、SSRC 映射、包恢复等关键环节,并提供了针对 XR+SFU 场景的调试建议。调试时可重点关注 FEC 包接收与媒体包恢复日志,以验证链路有效性。

HOSTEN的博客 55

A + B for you again(HDU-1867)(最长公共前缀和后缀)

A + B for you again Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7891    Accepted Submission(s): 1984 Problem Description Generall

殇星痕的博客 747

部署OpenClaw时设置环境变量提示export: not valid in this context的完整解决方案

OpenClaw环境变量设置错误解决方案 问题概述 在部署OpenClaw时设置环境变量出现"export: not valid in this context"错误,通常由以下原因导致: 在非交互式shell中使用export命令 在命令替换或管道中使用export 脚本文件包含Windows换行符(CRLF) 解决方案 修正脚本执行方式:确保export命令在正确的shell上下文中使用 使用source命令:通过. setup_openclaw.sh或source setup_op

博客 463

数据结构课程设计--基于知识图谱的中医食疗数据管理与应用

【代码】数据结构课程设计--基于知识图谱的中医食疗数据管理与应用。

M_inherit的博客 573

hdu 1867 A + B for you again(KMP灵活应用)

Generally speaking, there are a lot of problems about strings processing. Now you encounter another such problem. If you get two strings, such as “asdf” and “sdfg”, the result of the addition between ...

vocaloid01的博客 293

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

HDU 1867 A + B for you again (KMP应用)

HDU 1867 A + B for you again (KMP应用)

Tc的专栏 999

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

A + B for you again hdu1867(KMP的应用)

A + B for you again Generally speaking, there are a lot of problems about strings processing. Now you encounter another such problem. If you get two strings, such as “asdf” and “sdfg”, the result o

codeswarrior的博客 308

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

hdu 1867(A + B for you again) KMP的应用 /hdu 2594(Simpsons’ Hidden Talents) KMP

今天对KMP的认识又加深一点了,可是又不是很能用语言来表达! 题目大意:给定两个字符串,比如abcd,dcab,需要把它连接起来,但是需要遵循两个条件,1 最短原则 2 长度相同的前提下字典序的优先 连接原则:如果第一个字符串的后缀(长度为n)和第二个字符串的前缀(长度为n)相同,那么连接的时候可以省去相同的n个字符,本来有2n个字符; 仍然以上面的两个字符串为例,有两种连法,abcd...

weixin_30629977的博客 150

HDU 1867 A + B for you again 数据结构+KMP简单应用

A + B for you again 数据结构+KMP简单应用 Time Limit:1000MS    Memory Limit:32768KB    64bit IO Format:%I64d & %I64u SubmitStatus Description Generally speaking, there are a lot of problems about s

fans_ac的博客 343

【HDU - 1867 】A + B for you again(KMP,next数组应用)

题干: Generally speaking, there are a lot of problems about strings processing. Now you encounter another such problem. If you get two strings, such as “asdf” and “sdfg”, the result of the addition bet...

xuanweiace的博客 240

HDU 1867 A + B for you again(KMP算法的应用)

A + B for you again Time Limit: 5000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4496Accepted Submission(s): 1157 Problem Description Generally spea...

weixin_33734785的博客 135

HDU1867 A + B for you again【KMP】

A + B for you again Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 9765 Accepted Submission(s): 2410 Problem Description Generally speaking...

海岛Blog 735

【KMP】 hdu1867 A + B for you again

A + B for you again http://acm.hdu.edu.cn/showproblem.php?pid=1867 Problem Description Generally speaking, there are a lot of problems about strings processing. Now you encounter another su

Ted's 游乐园 1955

HDU - A + B for you again(KMP)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1867Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description Generally speaking, there are a lot of problem...

ityanger的技术栈 2670

hdu1867---A + B for you again

A + B for you again Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4633    Accepted Submission(s): 1192 Problem Description Generally

Alex 1160

【hdu1867】A + B for you again——KMP

题目: A + B for you again Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5914    Accepted Submission(s): 1463 Problem Description

CFhM_R's Blog 490

HDU 1867 A + B for you again kmp算法

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1867 题意:给定两个字符串,把一个字符串接在另一个字符串的后面,相接部位若有相同,则可以略去其中一个字符串的相同部分,输出拼接后最小长度的字符串,若有两种最小长度的字符串,输出字典序较小的那个 思路:可以用kmp匹配一个字符串的尾部和另一个字符串的首部相同的最大长度,然后交换两个字符串的次序,再来一次

弱智就要多努力 675

hdu 1867:A + B for you again(kmp)

http://acm.hdu.edu.cn/showproblem.php?pid=1867 Problem Description Generally speaking, there are a lot of problems about strings processing. Now you encounter another such problem. If you get two st...

300
上一篇: 【Linux是什么】Torvalds的Linux开发
下一篇: HDU1166 敌兵布阵 线段树 单点更新
Bill_Utada
博客等级 码龄12年 43粉丝 133原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值