字符串中最长子串

来源:互联网 发布:横道图绘制软件 编辑:程序博客网 时间:2024/05/16 17:29
#include <iostream>using namespace std;int fun(char *src,char *dst){char *p = src;char *s = NULL;int i = 0;int len = 0;int maxlen = 0;while(*p != '\0'){s = p;while((*s >= 'A' && *s <= 'Z') || (*s >= 'a' && *s <= 'z') )s++;len = s - p;if(len > maxlen){maxlen = len;i = 0;while(p < s)dst[i++] = *p++;//总是保存最长子串dst[i]='\0';}elsep++;}return maxlen;}void main(){char *s = "12345ILOVECHINA123456AGOODCOMPANY321";char dst[100];int a = fun(s, dst);printf("%d\n%s\n", a, dst);}

0 0
原创粉丝点击