Gistrec icon

Разбиение на слова

Gistrec | PRO | 12/30/18 06:27:08 AM UTC | 0 ⭐ | 870 👁️ | Never ⏰ | []
C++ |

610 B

|

None

|

0 👍

/

0 👎

#include <iostream>
#include <sstream>
#include <vector>
#include <string>
 
using namespace std;
 
vector<string> SplitIntoWords(const string& s) {
    vector<string> result;
    std::istringstream iss(s);
 
    string pice;
    while (std::getline(iss, pice, ' ')) {
        result.push_back(pice);
    }
    return result;
}
 
int main() {
    string s = "C Cpp Java Python";
 
    vector<string> words = SplitIntoWords(s);
    cout << words.size() << " ";
    for (auto it = begin(words); it != end(words); ++it) {
        if (it != begin(words)) {
            cout << "/";
        }
        cout << *it;
    }
    cout << endl;
 
    system("pause");
    return 0;
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎