输出连续(包括长度为1)串的个数
题目出自 abc143 - c
in:
10
aabbbbaaca
out:
5
in:
20
xxzaffeeeeddfkkkkllq
out:
10
void solve()
{
/**** data ****/
int n;
std::cin >> n;
std::string s;
std::cin >> s;
/**** core ****/
std::unordered_map<int, int> hash;
int cnt = 0;
for (int i = 0, j = 0; i < n; ++ i) {
hash[s[i]] ++;
if (hash[s[i]] == 1) ++ cnt;
while (s[i] != s[j]) {
hash[s[j]] --;
++ j;
}
}
std::cout << cnt << '\n';
}