首页 > 学院 > 开发设计 > 正文

find the longest numeric string in the given input strings

2019-11-06 06:39:22
字体:
来源:转载
供稿:网友

题目描述:对于一个输入的字符串,找出全是数字的最长的字符串

/*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;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表