c++ - Search string for string sequence -
this question has answer here:
what efficient way count number of occurrences of substring in string in c++? example, have huge string like
"gqwhiwqghwggeeegqihigwhiqwghieeegphiqpiwghqpwgpheeegqihwpwgqhpqwgeee"
and want count how "eee"
occurs.
i go step step in loop , check every letter if it's e , if so, count them , if there 3 e
s, increment counter, guess there more efficient way of doing this.
maybe string function? wasn't able find or google suitable one.
i searching clean c++11 solution.
well, if want fast , efficent solution, take @ knuth–morris–pratt algorithm - takes o(n+m) search. if want in stl style, take @ std::string::find
Comments
Post a Comment