sdut oj 1171 C语言实验 保留整数

C语言实验——保留整数

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

*47*456*23*9*

Hint

Source



#include <stdio.h>
#include <string.h>

int main()
{
    char s[100];
    int i, x;
    gets(s);
    x = strlen(s);
    for(i = 0; i <= x - 1; i++)
    {
        if(i == 0)
        {
            if(s[i] >= 48 && s[i] <= 57)
                printf("%c", s[i]);
            if((s[i + 1] >= 48 && s[i + 1] <= 57) && (s[i] < 48 || s[i] > 57))
            {
                printf("*");
                if(s[i] >= 48 && s[i] <= 57)
                    printf("%c", s[i]);
            }

        }
        else
        {
            if((s[i] >= 48 && s[i] <= 57) && (s[i - 1] < 48 || s[i - 1] > 57))
                printf("*");
            if(s[i] >= 48 && s[i] <= 57)
                printf("%c", s[i]);
            if((i == x - 1)&& (s[i] < 48 || s[i] > 57))
                printf("*");
        }
    }
    printf("\n");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/zx__zh/article/details/78919921