Huawei Machine Test-sub-string separation

Source: Internet
Author: User

Title Description:
Enter any string sequence through the keyboard, the string may contain multiple substrings, and the substrings are separated by a space. Write a program that automatically separates each substring and uses ', ' to separate it, and at the end adds a ', ' and stores the substring.
If you enter "ABC def GH i d", 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: Input string length
"Output" POUTPUTSTR: output string, space has been opened up, and input string length;
"Note" Only needs to complete the function algorithm, the middle does not need any IO input and output


Example

Input: "ABC def GH i d"

Output: "Abc,def,gh,i,d,"


#include <iostream> #include <string>using namespace std;//sub-string separation void dividestring (const char* PINPUTSTR, Long Linputlen, char* poutputstr)  {  int i,j=0;      BOOL Flag;      for (i = 0; Pinputstr[i] = = "; ++i)   //skip string preceded by Space              continue;      Flag = true;      for (; i < Linputlen; ++i)      {  if (pinputstr[i]! = ')          {  if (!flag) flag = true; poutputstr[j++] = pinputs Tr[i];    Detach each substring          and save it} else          {  if (flag) poutputstr[j++] = ', ';              Flag = false;          }      }      Poutputstr[j++] = ', ';      Poutputstr[j++] = ' + ';  } void Main () {char S[100];char result[100];while (gets (s)) {dividestring (S,strlen (s), result);cout<<result< <endl<<endl;} Cout<<endl;}


Test results, may not be thoughtful, welcome to check the leak:


Huawei Machine Test-sub-string separation

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.