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: