OJ题

时间:2023-03-09 19:24:37
OJ题

题目:在字符串中找出连续最长的数字串

#include <stdlib.h>
#include <string.h>
#include <iostream>
#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)
{

    if(!intputstr){
        *pOutputstr=NULL;
        ;
    }
    int strLength=strlen(intputstr);
    ;
    ;
    ;
    ;
    ;
    ;
    ;i<strLength;i++){
        '){
            tempStart=i;
            i=i+;
            '){
                i++;
            }
            tempEnd=i;
            tempLength=tempEnd-tempStart;
        }
        if(tempLength>=maxLength){
            maxLength=tempLength;
            maxLenStart=tempStart;
            maxLenEnd=tempEnd;
        }
    }
    char * result;
    //无数字的时候返回""空字符串
    ){
        result=(char*)(malloc(sizeof(char)));
    }else
    {
        result=()));
        ;i<maxLength;i++)
        {
            result[i] = (char)intputstr[i+maxLenStart];
        }
    }
    result[maxLength]='\0';
    *pOutputstr=result;
    //pOutputstr=&result;
    return maxLength;
}