题目描述:对于一个输入的字符串,找出全是数字的最长的字符串
/*find teh longest numeric string */#include <stdio.h>#include <cytpe.h>int main(){ char* pos = NULL; int maxlen = -1; char* curpos = NULL; int curlen = 0; char str[30] = {0}; PRintf("input string/n"); scanf("%s",str); char *p = curpos = str; while(*p != 0) { if(!isdigit(*p)) { curlen = 0; curpos = p; curpos++; } else { curlen ++; if(curlen>maxlen) { maxlen = curlen; pos = curpos; } } p++; } if(maxlen) { printf("the logest numeric string is:/n"); for(int i=0;i<maxlen;i++) { printf("%c",pos[i]); } } else printf("no match result/n"); return 0;}新闻热点
疑难解答