1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include<iostream> #include<unordered_map> int main() { std::string example = "abcbabc"; std::unordered_map<char, int> mp; int cnt = 1; for(char c : example) { if(mp[c] > 0) { ++cnt; mp.clear(); } mp[c]++; } std::cout << cnt; }