题解 | #表示数字#
表示数字
https://www.nowcoder.com/practice/637062df51674de8ba464e792d1a0ac6
#include <stdio.h> #include <string.h> #include <ctype.h> int main() { char str[100] = {0}; char str1[200] = {0}; while (scanf("%s", str) != EOF) { // 注意 while 处理多个 case int len = strlen(str); int i = 0,k = 0; for(i=0, k=0; i<len; i++,k++) { //if((str[i] >= '0' && str[i] <= '9' ) && (str[i-1] < '0' && str[i-1] >'9') )//为什么这样判断不了? if((!isdigit(str[i-1])) && isdigit(str[i]) ) { str1[k++] = '*'; //k++; str1[k] = str[i]; } else if(!isdigit(str[i]) && isdigit(str[i-1]) ) { str1[k++] = '*'; //k++; str1[k] = str[i]; } else { str1[k] = str[i]; } } if(isdigit(str[len-1])) { strcat(str1,"*"); } for(int j = 0; j<strlen(str1); j++) { printf("%c",str1[j]); } printf("\n"); } return 0; }