MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / split_string

Function split_string

Hackerrank_problems/kangaroo/solution5.cpp:86–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84}
85
86vector<string> split_string(string input_string) {
87 string::iterator new_end = unique(input_string.begin(), input_string.end(), [] (const char &x, const char &y) {
88 return x == y and x == ' ';
89 });
90
91 input_string.erase(new_end, input_string.end());
92
93 while (input_string[input_string.length() - 1] == ' ') {
94 input_string.pop_back();
95 }
96
97 vector<string> splits;
98 char delimiter = ' ';
99
100 size_t i = 0;
101 size_t pos = input_string.find(delimiter);
102
103 while (pos != string::npos) {
104 splits.push_back(input_string.substr(i, pos - i));
105
106 i = pos + 1;
107 pos = input_string.find(delimiter, i);
108 }
109
110 splits.push_back(input_string.substr(i, min(pos, input_string.length()) - i + 1));
111
112 return splits;
113}

Callers 1

mainFunction · 0.70

Calls 1

minFunction · 0.85

Tested by

no test coverage detected