面试题---求一个串中的最大连续递增数字串
#include <stdio.h> #include <string.h> #include <stdlib.h> void max(char *str) { char *p = str; int max_len = 0; char *max_start = NULL; while(*p != '\0') { if(*p >= '0' && *p <= '9') { int len = 1; char *q = p; while((*q != '\0') && (*q >= '0' && *q <= '9') && (*(q + 1) == *q + 1)) { len++; q++; } if(len > max_len) { max_len = len; max_start = p; } p = q + 1; } p++; } if(max_start != NULL) { fwrite(max_start,max_len,1,stdout); printf("\n"); } } int main() { printf("输入第一个字符串:\n"); char str[256]; scanf("%s",str); printf("%s\n",str); max(str); return 0; }