问题标题: 酷町堂:找数字!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

1
1
胡景轩
胡景轩
资深守护
资深守护

题目链接: 酷町堂:4032

题目描述 De**ion

现在给出一个仅包含数字和字母的字符串,请你找出其中的所有连续数字。

输入描述 Input De**ion

一个仅包含字母和数字的字符串

输出描述 Output De**ion

每个数字占一行,不包含前导0,即如果出现00123,那么输出123;如果该数字为0,需要输出。

样例输入 Sample Input

abc12de0ccc0514F9

样例输出 Sample Output

12 0 514 9

数据范围及提示 Data Size & Hint

对于90%的数据:字符串最后一位不是数字;
对于100%的数据:字符串长度不超过1000;

注意:需要考虑最后一位是数字的情况。

#include<iostream>

#include<cstdio>

#include<cmath>

#include<string>

#include<algorithm>

#include<cstring>

using namespace std;

int main(){

    int st,ed,len,m=0,d[1005];

    string a;

cin>>a;

for(int i=0;i<a.size();i++){

if(a[i]>='0'&&a[i]<='9'&&a[i-1]>=64&&a[i-1]<=150){

st=i;

}

    if(a[i]>='0'&&a[i]<='9'&&a[i+1]>=64&&a[i+1]<=150){

ed=i;

len=ed-st+1;

d[++m]=a.substr(st,len);

}

for(int j=0;j<d[m].size();j++){

while(d[j]=='0'){

    d[j].erase(j,1);

            }

        }

        if(d[j]==""){

            cout<<0<<endl;

        }else{

            cout<<d[j]<<endl;

        }

}

return 0;

}


0
我要回答