字符串求数字长度

来源:互联网 发布:北京 软件编程培训班 编辑:程序博客网 时间:2024/05/16 15:18
#include <stdio.h>#include <iostream>#include <cstring>#include <stdlib.h>#include <math.h>using namespace std;void outhanshu(char *str,int end,int max){       for(int j=end-max+1;j<=end;j++){           cout<<str[j];       }}int main(){    char str[1005];    while(cin.getline(str,1000)){    int length=strlen(str);    int count=0;    int max=0;    int end=-1;    for(int i=0;i<length;i++){        if(str[i]<='9'&&str[i]>='0'){           count++;           if(max<count){              max=count;              end=i;           }        }        else{            count=0;        }       }    if(max==0){       cout<<"";    }    else{        int count1=0;        int end1=-1;        for(int i=0;i<length;i++){            if(str[i]<='9'&&str[i]>='0'){               count1++;               if(max==count1){                  end1=i;                  outhanshu(str,end1,max);               }             }            else{                count1=0;            }        }       cout<<',';       cout<<max<<endl;    }    }    return 0;}
原创粉丝点击