2273: 找整数(串)
Time Limit: 1 Sec Memory Limit: 128 MB Submit: 20 Solved: 7 [ Submit][ Status][ Web Board]Description
输出任意的一个字符串内(字符串内可以包含空格)的所有整数。输出时两整数间有四个空格。
Input
输入一串字符
Output
输出所有的整数
Sample Input
a00asd123e24
Sample Output
0 123 24
#include <iostream>
#include <cstdio>
#include <cstring>
using
namespace
std;
int
output(
char
a[])
{
int
n,i,sum=0,m=999;
n=
strlen
(a);
for
(i=0;i<n;i++)
{
if
(a[i]!=
'0'
){m=i;
break
;}
}
for
(i=m;i<n;i++){cout<<a[i];}
if
(m==999){cout<<
'0'
;}
cout<<
" "
;
}
int
panduan(
char
c)
{
return
(c>=
'0'
&&c<=
'9'
);
}
int
main()
{
char
s[9999],a[99][999];
int
n,i,j=1,k=0;
gets
(s);
n=
strlen
(s);
for
(i=0;i<n;i++)
{
if
(panduan(s[i]))
{
a[j][k++]=s[i];
}
if
(panduan(s[i])&&!panduan(s[i+1]))
{
j++;
k=0;
}
}
for
(i=1;i<j;i++)
{
output(a[i]);
}
}
ytu 2273: 找整数(串)
最新推荐文章于 2020-04-23 22:33:10 发布