Advertisement
Guest User

Untitled

a guest
Nov 20th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using std::cout;
  5. using std::cin;
  6. using std::vector;
  7. using std::string;
  8.  
  9. void Input(string *line, char &symbol) {
  10.     cin >> *line >> symbol;
  11. }
  12.  
  13. vector<string> Split(string const &line, char symbol) {
  14.     vector<string> result;
  15.     for (int s(0), j(0), i(0); i < line.size(); ++i) {
  16.         if (line[i] == symbol) {
  17.             result.push_back(line.substr(j , (i - j)));
  18.             j = i + 1;
  19.             ++s;
  20.         }
  21.         if (i == line.size() - 1) {
  22.             result.push_back(line.substr(j , (i - j + 1)));
  23.         }
  24.     }
  25.     return result;
  26. }
  27.  
  28. void Output(vector<string> &answer) {
  29.     for(vector<string>::iterator i = answer.begin(); i != answer.end(); ++i) {
  30.         cout << *i << "\n";
  31.     }
  32. }
  33.  
  34. int main() {
  35.     string line;
  36.     char symbol;
  37.     Input(&line, symbol);
  38.     Output(Split(line, symbol));
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement