Quick actions

cmd+k|ctrl+k

Navigation

Languages

substring chain

Snippet info

Language

Cpp

Visibility

public

Author

eduardobilk

Created

2017-02-14T16:45:12Z

Updated

2017-02-16T10:55:31Z

#include <iostream>
#include <string>
using namespace std;

int main() {
    string x;
    cin >> x; // input simulado = banana.batata.tomato.buzz.fuzz.chuzz.bop.nop.chuck
    size_t found = x.find(".");

    while (found != std::string::npos){ //loop enqunato encontrar "." na string
        cout << x.substr(0,x.find(".")) << endl;// acha a primeira parte 
        x = x.substr(x.find(".")+1); // atribui ao x o resto da string
        found = x.find("."); //grava a posição que o "." esta
    }
    cout << x << endl;// printa a ultima parte da string (que não tem ".")
    return 0;
}
INFO