String Splitting


Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
C++, Python3

You are required to write lab3p2.cpp and implement a function that splits a string object by +, -, and , without removing them.

Here's the function prototype:

void split(std::string src, std::string* ans);

This function will detect the characters +, -, and whitespaces, and store the split segments into the ans array.

For example, given src equals:

"I like+cheese,-how about+you?"

the value of ans should be:

["I", "like", "cheese,", "how", "about", "you?"]

After you are done, upload the content of your lab3p2.cpp onto the OJ here.

Input Specification

No input specification. OJ will automatically judge your implementation of lab3p2.cpp.

Output Specification

No output specification. OJ will automatically judge your implementation of lab3p2.cpp.


Comments


  • 0
    jetic  commented on July 19, 2020, 4:17 p.m.

    Hint: here's the code for the main programme used in evaluation:

    #include <iostream>
    #include <iomanip>
    #include "lab3p2.h"
    using namespace std;
    
    string ans[100];
    
    int main() {
        string instr;
    
        while (getline(cin, instr)) {
            for (int i=0; i<100; i++)
                ans[i].clear();
            split(instr, ans);
            int i=0;
            while (i < 100) {
                if (ans[i].length() != 0)
                    cout << ans[i] << ' ';
                i++;
            }
            cout << endl;
            instr = "";
        }
        return 0;
    }