您的位置:首页 > 其它

求最大连续递增数字串(如“ads3sl456789DF3456ld345AA”中的“456789”)

2012-08-02 17:31 309 查看
求最大连续递增数字串(如“ads3sl456789DF3456ld345AA”中的“456789”)

void findx(char *str)

{

int i , j, m,k ,tmp,start,end,count[100] ,count_1[100] ,count_2[100];

i =0;

k = 0;

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

{

if((str[i]>='0')&&(str[i]<='9'))

{

m = i;

while((str[m]>='0')&&(str[m]<='9')&&(str[m+1]>='0')&&(str[m+1]<='9')&&(str[m+1] > str[m]))

{

m++;

}

count[k] = m-i;

count_1[k] = i;

count_2[k] = m;

k++;

}

i++;

}

for(i = 0;i<k-1 ;i++)

{

if(count[i+1]<count[i] )

{

tmp = count[i];

count[i] = count[i+1];

count[i+1] = tmp;

}

}

for(i = 0 ;i<k ;i++)

{

if(count[k-1] == (count_2[i] - count_1[i]))

{

start = count_1[i];

end = count_2[i];

}

}

for(i = start ;i<=end ; i++)

{

cout<<str[i]<<endl;

}

}

void main()

{

char *str="ab12c34567def78";

findx(str);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: