Exam --- eliminate unnecessary Spaces

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.