View Code of Problem 50

//需要引入#include <ctype.h> 
//isalnum() 判断一个字符是否是数字或者字母
//isdigit() 判断一个字符是否是数字
#include<stdio.h>
#include <ctype.h> 
int main() {
	char str1[100], str2[100];
	int count1=0,count2=0,i,j; 
	gets(str1);
	// 计算str1的长度 
	while(str1[count1]!='\0') count1++;
	for(i=0; i<=count1;) {
		if(isdigit(str1[i])) str2[count2++]=str1[i++];
		else {
			for(j=i+1; j<=count1;j++) if(isdigit(str1[j])) break;
			if(j-i != 1) {
				str2[count2++]='*';
				i=j;	
			}
			else i++;
		}
	}
	for(int k=0; k<count2; k++) printf("%c", str2[k]);
}

Double click to view unformatted code.


Back to problem 50