写一个函数找出连续最长的数字串

来源:互联网 发布:12月份php好找工作吗 编辑:程序博客网 时间:2024/06/07 02:24

简单题。。 

  1 #include <iostream>  2 using namespace std;  3 int continueNum( char *str, char *intput )  4 {  5     int n = 0, maxcount = 0, count = 0;  6     char *p = str, *maxp = NULL, *indexp = NULL;  7     while( *p != '\0' )  8     {  9         if( *p >= '0' && *p <= '9' ) 10         { 11             if( count++ == 0)indexp = p; 12             if(count > maxcount) 13             { 14                 maxp = indexp; 15                 maxcount = count; 16             }    17         }    18         else 19         { 20             count = 0; 21         }    22          23         p++; 24     }    25     n = maxcount; 26     while( n-- ) 27     { 28         *intput++ = *maxp++; 29          30     }    31     return maxcount; 32 }    33 int main() 34 { 35     char str[100] = "345as3456ty78"; 36     char intput[100] = {0}; 37     cout <<continueNum(str,intput) << endl; 38     cout << intput << endl; 39     return 0; 40 }   


0 0
原创粉丝点击