算法100题25
2011-10-06 19:04 justvi 阅读(387) 评论(3) 编辑 收藏 举报/* 题目来自:http://blog.csdn.net/v_JULY_v
* 写一个函数,它的原形是int continumax(char *outputstr,char *intputstr)
* 功能:
* 在字符串中找出连续最长的数字串,并把这个串的长度返回,
* 并把这个最长数字串付给其中一个函数参数outputstr所指内存。
* 例如:"abcd12345ed125ss123456789"的首地址传给intputstr后,函数将返回9,
* outputstr所指的值为123456789
*/
int continuemax(char *outputstr, char *inputstr)
{
char *plong, *pcompare;
char *s = inputstr;
int llen, clen;
llen = clen = 0;
int i;
while (*s != '\0')
{
while (!isdigit(*s))
s++;
if (isdigit(*s))
pcompare = s;
while (isdigit(*s))
{
s++;
clen++;
}
if (clen > llen)
{
llen = clen;
plong = pcompare;
//clen = 0;
}
clen = 0;
}
for (i = 0; i < llen; i++)
outputstr[i] = plong[i];
outputstr[i] = '\0';
return llen;
}
int main()
{
char instr[] = "abcd12345ed125ss123456789";
int len;
char *out = instr;
len = continuemax(out, instr);
printf("%d, %s\n", len, out);
return 0;
}
作者:justvi
出处:http://www.cnblogs.com/justvi/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章正文中给出原文连接,否则保留追究法律责任的权利
出处:http://www.cnblogs.com/justvi/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章正文中给出原文连接,否则保留追究法律责任的权利