图片附件: 游客没有浏览图片的权限,请
登录 或
注册
MaxContinuNum这个要简单点:
程序代码:
#include <stdio.h>
#define MAX_LENGTH 1023
#define IS_NUMBER(ch) ((ch) >= '0' && (ch) <= '9')
char* stringCopy(char* to, const char* from, int length);
int maxContinuNum(const char* inputstr, char* outputstr);
void test(const char* inputstr, char* outputstr);
int main(void) {
char buffer[MAX_LENGTH + 1];
test("abcd12345ed125ss123456789", buffer);
test("123456m12345mz1mzm12mm123mm1234567mz1", buffer);
test("1dfadfjklgfn22", buffer);
}
char* stringCopy(char* to, const char* from, int length) {
int i;
for (i = 0; i < length; ++i)
to[i] = from[i];
to[i] = '\0';
return to;
}
int maxContinuNum(const char* inputstr, char* outputstr) {
int count = 0, i, j;
const char* mark = 0;
for (i = 0; inputstr[i]; ++i) {
if (IS_NUMBER(inputstr[i])) {
for (j = 0; IS_NUMBER(inputstr[i + j]); ++j)
;
if (count < j) {
count = j;
mark = inputstr + i;
}
i = i + j - 1;
}
}
if (count)
stringCopy(outputstr, mark, count);
return count;
}
void test(const char* inputstr, char* outputstr) {
int count = 0;
printf("inputstr: %s\n", inputstr);
count = maxContinuNum(inputstr, outputstr);
printf("count: %d\n", count);
printf("outputstr: %s\n\n", outputstr);
}