日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

找出连续最长数字串python_字符串中找出连续最长的数字字符串的实例代码

發布時間:2024/9/19 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 找出连续最长数字串python_字符串中找出连续最长的数字字符串的实例代码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

//1. 寫一個函數,它的原形是int continumax(char *outputstr,char *intputstr)

//功能:

//在字符串中找出連續最長的數字串,并把這個串的長度返回,

//并把這個最長數字串付給其中一個函數參數outputstr所指內存。

//例如:"abcd12345ed125ss123456789"的首地址傳給intputstr后,函數將返回9,outputstr所指的值為123456789

#include

#include

int continumax(char *outputstr,char *inputstr)

{

assert(outputstr);

assert(inputstr);

int length = 0;

int maxlength = 0;

int i = 0;

int j = 0;

while(inputstr[i] != '\0')

{

while( inputstr[i] >='0'&& inputstr[i] <= '9')

{

length++;

i++;

}

if(length > maxlength)

{

maxlength = length;

int k = i-maxlength;

for(j = 0; j < maxlength; j++ )

{

outputstr[j] =inputstr[k++];

}

length = 0;

continue;

}

i++;

length = 0;

}

outputstr[j] = '\0';

return maxlength;

}

int main( )

{

char inputstr[ ]= "abcd12345eddafsd125ss123456789";

char outputstr[100];

int max_numstr_length = continumax(outputstr,inputstr);

printf("%s\n",outputstr);

printf("the max_numstr_length is %d\n", max_numstr_length);

return 0;

}

#include

#include

int continumax(char * outputstr, char * inputstr)

{

int len = 0;??????? //統計數字字符串的長度

int max = 0;??????? //當前最大數字字符串的長度

char *pstr =NULL;?? //記錄最大數字字符的起始位置

while(* inputstr!= '\0')

{

if(*inputstr <= '9' && *inputstr >='0')? //統計數字子字符串的長度

{

len++;

inputstr++;

continue;

}

else if (len > max)??????? //如果統計出來的數字字符串大于當前的最大數字子字符串的長度,則更新

{

max = len;

pstr = inputstr-len;

len = 0;

}

inputstr++;

}

for(int i = 0 ; i

{

*outputstr = *pstr;

outputstr++;

pstr++;

}

outputstr = outputstr-max;

outputstr[max] ='\0';

cout<

return max;

}

int main()

{

char input[] = "de1234de123456ed";

//char * out = (char *)malloc(100*sizeof(char));

char output[100];

int max = continumax(output, input);

cout<

return 0;

}

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的找出连续最长数字串python_字符串中找出连续最长的数字字符串的实例代码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。