#include<stdio.h> #include<math.h> #include<string.h> int main(int argc, char** argv) { /* 输入一个字符串str1,把其中的连续非数字的字符子串换成一个‘*’,存入字符数组str2 中,所有数字字符也必须依次存入 str2 中。输出str2。 */ char str[90]; char str2[90]; gets(str); int i , j =0 ; for( i = 0 ; i <strlen(str) - 1 ; i++){ if( ( str[i] <'1' || str[i] >'9') && str[i + 1] >= '1' && str[i + 1] <= '9' ){ str2[j++] = '*'; } if( str[i] >= '1' && str[i] <= '9' ){ str2[j++] = str[i]; } } if( str[i] <'1' || str[i] >'9' ) str2[j] = '*'; else str2[j] = str[i]; // if( ( str[i] <'1' || str[i] >'9') && ( str[i+1] <'1' || str[i+1] >'9') ){ // str2[j++] = '*'; // }else{ // str2[j++] = str[i++]; // str2[j++] = str[i++]; // } for(i = 0 ; i < strlen(str2) ; i++){ printf("%c" , str2[i]); } return 0 ; } |
Double click to view unformatted code.