查找字符串中字符不重复的最大子串(C/C++)
//输入参数:*str 搜索字符串
// subStrLen 用于返回找到的最大子字符串长度
//返回:找到的最大子字符串指针
char * findMaxSubStr(char *str, int &subStrLen){
char *subStr;
char *p = str;
int index[256] ;
for (int ix = 0; ix < sizeof(index)/sizeof(index[0]); ix++)
{
index[ix] = -1;
}
int subStrPos = 0; // 子字符串在字符串str中的偏移
int charPos = 0; // 当前字符在字符串str中的偏移
int currLen = 0; //当前子字符串长度
int maxLen = 0; //已经找到的最大子字符串长度
char ch;
while (ch = *p)
{
if (index[ch] < subStrPos){ //字符首次出现 或者 字符在子字符串开始的位置后首次出现
index[ch] = charPos;
currLen++;
}else {
currLen = charPos - index[ch];
subStrPos = ++index[ch];
index[ch] = charPos;
}
if (currLen > maxLen)
{
subStr = str + subStrPos;
maxLen = currLen;
}
p++;
charPos++;
}
subStrLen = maxLen;
return subStr;
}
相关文档:
我用的是ubuntu操作系统。打开终端
1.sudo apt-get install vim(vim-full 这个软件自9.10版本被废弃了,不论怎么添加软件源都找不到的,所以直接安装vim就可以了,,也可以安装gvim,,在新立得软件里面搜索vim就可以找到了)
2.
sudo apt-get install build-essential // build-essential是c语言的开发包,包含了gcc ma ......
以 i2c-mpc.c 驱动模块为例
fsl_i2c_init -> of_register_platform_driver -> of_register_driver -> driver_register -> bus_add_driver -> driver_attach
-> bus_for_each_dev -> __driver_attach -> driver_probe_device -> really_probe -> drv->probe(dev); ......
1. 什么是空指针常量(null pointer constant)?
[ 6.3.2.3-3] An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.
这里告诉我们:0、0L、'\0'、3 - 3、0 * 17 (它们都是“integer constant expression”)以及 ......
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/wait.h>
#define QLEN 20
# ......