Huawei test-Child string separation and Huawei string Separation

Source: Internet
Author: User

Huawei test-Child string separation and Huawei string Separation
Description:
Input any string sequence through the keyboard. The string may contain multiple substrings separated by spaces. Compile a program to automatically separate the substrings and separate them with commas (,). At the end, add a comma (,) and store the substrings.
If "abc def gh I d" is input, the result will be abc, def, gh, I, d,
 
Required implementation functions:
Void DivideString (const char * pInputStr, long lInputLen, char * pOutputStr );
 
[Input] pInputStr: input string
LInputLen: length of the input string
[Output] pOutputStr: Output string. The space has been opened up and the length of the input string is equal to that of the input string;
[Note] You only need to complete the function algorithm, and there is no IO input or output in the middle.


Example

Input: "abc def gh I d"

Output: "abc, def, gh, I, d ,"


# Include <iostream> # include <string> using namespace std; // substring separation void DivideString (const char * pInputStr, long lInputLen, char * pOutputStr) {int I, j = 0; bool flag; for (I = 0; pInputStr [I] = ''; ++ I) // skip the space before the string and continue; flag = true; for (; I <lInputLen; ++ I) {if (pInputStr [I]! = '') {If (! Flag) flag = true; pOutputStr [j ++] = pInputStr [I]; // separate and save each substring} else {if (flag) pOutputStr [j ++] = ','; flag = false ;}} pOutputStr [j ++] = ','; pOutputStr [j ++] = '\ 0';} void main () {char s [100]; char result [100]; while (gets (s )) {DivideString (s, strlen (s), result); cout <result <endl ;}cout <endl ;}


Test results may be incomplete. Check for missing information:


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.