#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "oj.h"
using namespace std;
/* 功能:在字符串中找出连续最长的数字串,并把这个串的长度返回
函数原型:
unsigned int Continumax(char** pOutputstr, char* intputstr)
输入参数:
char* intputstr 输入字符串
输出参数:
char** pOutputstr: 连续最长的数字串,如果连续最长的数字串的长度为0,应该返回空字符串
pOutputstr 指向的内存应该在函数内用malloc函数申请,由调用处负责释放
返回值:
连续最长的数字串的长度
*/
unsigned int Continumax(char** pOutputstr, char* intputstr)
{
char *pStart = intputstr;
int count = 0;
int maxlen = 0;
char *pTmp = NULL;
while(*pStart != '\0')
{
if (*pStart>='0' && *pStart<='9')
{
count++;
}
else
{
if (maxlen<=count)
{
maxlen = count;
pTmp = pStart - count;
}
}
pStart++;
}
if (maxlen==0)
{
const char a=' ';
return a;
}
else
{
char *pRes = (char*)malloc((maxlen+1)*sizeof(char));
strncpy(pRes, pTmp, maxlen);
pRes[maxlen] = '\0';
printf("%s", pRes);
free(pRes);
return maxlen;
}
return 0;
}