C语言实验——保留整数 SDUT

C语言实验——保留整数 SDUT

Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic
Problem Description

输入一个字符串str1,把其中的连续非数字的字符子串换成一个‘*’,存入字符数组str2 中,所有数字字符也必须依次存入 str2 中。输出str2。

Input

输入为一行字符串str1,其中可能包含空格。字符串长度不超过80个字符。

Output

输出处理好的字符串str2。

Sample Input

$Ts!47&s456 a23 +B9k

Sample Output

47456239*

include <stdio.h>
include <string.h>
include <memory.h>
int main()
{
char a[100], b[100];
int n, i, m=0;
gets(a);
n = strlen(a);
if( a[0] >= ‘0’ && a[0] <= ‘9’)
{
b[m++] = a[0];
}
else
{
b[m++] = ‘’;
}
for( i=1; i<n; i++ )
{
if( a[i]>=‘0’ && a[i]<=‘9’ )
{
b[m++] = a[i];
}
else
{
if( b[m-1] != '
’ )
{
b[m++] = ‘*’;
}
}
}
for( i=0; i<m; i++ )
{
printf("%c", b[i]);
}
printf("\n");
return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43892738/article/details/85708653