#include <stdlib.h>
#include "oj.h"
typedef struct node
{
char data;
struct node *next;
int flags;
int data_count;
}*LinkList,LinkNode;
LinkList total_list;
/* 功能:在字符串中找出连续最长的数字串,并把这个串的长度返回
函数原型:
unsigned int Continumax(char** pOutputstr, char* intputstr)
输入参数:
char* intputstr 输入字符串
输出参数:
char** pOutputstr: 连续最长的数字串,如果连续最长的数字串的长度为0,应该返回空字符串
pOutputstr 指向的内存应该在函数内用malloc函数申请,由调用处负责释放
返回值:
连续最长的数字串的长度
*/
unsigned int Continumax(char** pOutputstr, char* intputstr)
{
LinkNode *pre,*q;
char *string;
int count = 0;
int data_flag = 0;
int i = 0;
int max_count = 0;
string = intputstr;
pOutputstr = (char **)malloc(sizeof(char *));
total_list = (LinkList)malloc(sizeof(LinkNode));
q = total_list;
while(*string != '\0')
{
//是数字,data_flag为1;不是数字,data_flag为0;
if((*string >= '0') && (*string <= '9'))
{
pre = (LinkNode *)malloc(sizeof(LinkNode));
pre->data = *string;
pre->data_count = 0;
//是连续数字,flags标志位为0
if(data_flag)
{
pre->flags = 0;
count++;
}
//不是连续数字,重新计数,第一个数字的标志位为1
else
{
pre->flags = 1;
count = 1;
}
q->next = pre;
q = pre;
pre->next = NULL;
data_flag = 1;
}
else
{
data_flag = 0;
q->data_count = count;
}
string++;
}
q = total_list->next;
pre = q;
while(q)
{
if(q->flags == 1)
{
if(max_count <= i)
{
max_count = i;
pre = q;
}
}
else
{
i++;
}
q = q->next;
}
**pOutputstr = q->data;
return 0;
}