Question: first, replace * in the string with 0, and then normalize the nonstandard number.
For example: 1. *, 02.3*0, 12 *. 210,012.5 *, 4*560.0, 45*0
Step 1 Replace: 1.0, 02.300, 120.210, 012.50, 40560.0, 4500
Step 2 Normalization: 1, 2.3, 120.21, 12.5
The program code (based on the C language) is as follows:
Replace the Code:
Void change (char * string) // string is a char array
{int len = strlen(string);for (int i=0; i<len; i++){if (string[i] == '*') {string[i] = '0';}}}
The following Code standardizes the number:
Void Replace (char * string) {char * temp; bool isfloat = false; int Len = strlen (string); Len = len-1; // remove the excess zero for (INT I = 0; I <Len; I ++) {If (string [I] = '0 ') {Len = len-1;} else {break;} int Gap = strlen (string)-len-1; // to remove the "\ n ", GAP is the number of 0 printf ("---------- % d \ n", strlen (string)-1, GAP); For (INT I = 0; I <Len; I ++) {string [I] = string [I + Gap];} string [Len] = '\ 0'; // determines whether it is folat, if yes, remove the following 0for (INT I = 0; I <Len; I ++) {If (string [I] = '. ') // encountered. stop the scan and remove the zero operation {isfloat = true;} If (isfloat) {While (string [len-1] = '0 ') | (string [len-1] = '. ') {Len = len-1; if (string [len-1] = '. ') {Len = len-1; break;} string [Len] =' \ 0 ';}}
Program source code: http://download.csdn.net/detail/wangyingjun321/5541205