5- prove safety offer- face questions replace spaces - String

/ * 
Title: 
	Please implement a function, the replacement string into each of the spaces '% 20'. 
	For example enter "We are happy", the output "We% 20are% happy". 
* / 
/ * 
Concluding thoughts: 
	consider given enough memory array, and can not open up a new situation array. 
	Two pointers, copied from the back. 
	Note that the array is the last character '\ 0'. 
* / 
Void replaceBlank (STR char [], int length) { 
	IF (STR length == null || <= 0) { 
		return; 
	} 
	int blankNum = 0; 
	int index = 0; 
	int originLength = 0; 
	the while (STR [ index] = '\ 0')! { 
		IF (STR [index] == '') { 
			blankNum ++; 
		} 
		index ++; 
		originLength ++; 
	} 
	
	int = originLength the newLength + 2 * blankNum; 
	IF (length <the newLength) return;
	int = indexOfOrigin originLength; 
	int = indexOfNew newLength; 
	while (indexOfOrigin <indexOfNew && indexOfOrigin> = 0) {//标准答案加了indexOfOrigin> = 0,不明白意义
		if (p [indexOfOrigin]! = '') { 
			p [indexOfNew--] = p [indexOfOrigin]; 
		} else { 
			p [indexOfNew--] = '0'; 
			p [indexOfNew--] = '2'; 
			p [indexOfNew--] = '%'; 
		} 
		IndexOfOrigin--; 
	} 
	
	
	
	
}

  

Guess you like

Origin www.cnblogs.com/buaaZhhx/p/11801882.html