OJ5

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值