Written test questions:
If you enter a string "Lan Zhihui is a good boy! ", Now you need to remove the leading space of the string. Leave a space between each word to return" Lan Zhihui is a good boy! ".
# Include <iostream> using namespace STD; void fun (char a [], char B []) {int Len = strlen (a); bool falg = false; bool Sf = false; Int J = 0; For (INT I = 0; I <Len; I ++) {While (A [I] = ''&&! Falg) // falg is guaranteed to only enter once, that is, only the spaces in front of the string are ignored {I ++;} falg = true; if (a [I]! = '') {B [J] = A [I]; j ++; Sf = false;} else if (! SF) // record only one space at a time {B [J ++] = ''; Sf = true ;}} if (B [J-1] = '') // if the last character is a space, the last character is modified to '\ 0', {B [J-1] =' \ 0 ';} else {B [J] = '\ 0' ;}} int main () {char a [100]; char B [100]; gets (a); fun (, b); cout <B <Endl; System ("pause"); Return 0 ;}
Exam --- eliminate unnecessary Spaces