1 solutions

  • 0
    @ 2025-3-3 16:33:48

    C :

    #include<stdio.h>
    #include<string.h>
    int main()
    {
    	char a[80],b[80];
    	int x,i=0,j=0;
    	gets(a);
    	x=strlen(a);
    	if(a[i]>=48&&a[i]<=57)
    	{
    		b[j]=a[i];
    		j++;
    	}
    
    	else
    	{
    		b[j]='*';
    		j++;
    	}
    i=1;
    	while(i<=(x-1))
    	{
    		if(a[i]>=48&&a[i]<=57)
    		{
    			b[j]=a[i];
    			j++;
    		}
    		else if(b[j-1]!='*')
    		{
    			b[j]='*';
    			j++;
    		}
    		i++;
    
    	}
    	b[j]='\0';
    	puts(b);
    }
    

    Python :

    str1=input()
    str2 = ""
    f = True   # True 表示没有打印*
    for i in range(0,len(str1)):        
        if not str1[i].isdigit():   #判断字符串里的字符是否为数字
           if f:                    #如果不是数字切没有打印过* 那么在str2字符串中新增*
             str2 += "*"
             f = False
        else:                       #如果是数字  直接添加进str2
           str2 += str1[i]
           f = True
    print(str2)
    
    • 1

    Information

    ID
    10729
    Time
    1000ms
    Memory
    16MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By