Split string into words

后端 未结 4 1195
予麋鹿
予麋鹿 2021-02-03 13:27

I am looking for the most efficient algorithm to form all possible combinations of words from a string. For example:

Input String: forevercarrot

Output:

foreve         


        
4条回答
  •  名媛妹妹
    2021-02-03 14:06

    Input String: forevercarrot

    Output:

    forever carrot forever car rot for ever carrot for ever car rot

    program :

    #include
    #include
    #include
    #include
    void strsplit(std::string str)
    {
       int len=0,i,x,y,j,k;
       len = str.size();
       std::string s1,s2,s3,s4,s5,s6,s7;
       char *c = new char[len+1]();
       char *b = new char[len+1]();
       char *d = new char[len+1]();
       for(i =0 ;i< len-1;i++)
       {
           std::cout<<"\n";
           for(j=0;j<=i;j++)
           {
              c[j] = str[j];
              b[j] = str[j];
              s3 += c[j];
              y = j+1;
           }
           for( int h=i+1;h "<<"\n";
        else{
                    str = argv[1];
                    strsplit(str);
        }
    
    return 0;
    }
    

提交回复
热议问题