You are viewing a single comment's thread. Return to all comments →
class point{ public: char key; long count; point(char key,long count){ this->key = key; this->count = count; } };
int main() { std::vector _v; long count = 1; int n; scanf("%d",&n); char str[n]; std::cin >> str; char ch = str[0];
for(int i = 1; i <= n; i++) { if (ch == str[i]) count += 1; else { _v.push_back(point(ch,count)); count = 1; ch = str[i]; } } count = 0; for(auto p : _v) count += (p.count * (p.count + 1)) / 2; for(int i = 1; i < _v.size() - 1; i++) { if (_v[i - 1].key == _v[i + 1].key && _v[i].count == 1) count += std::min(_v[i - 1].count,_v[i + 1].count); } printf("%ld\n",count); return 0;
}
Seems like cookies are disabled on this browser, please enable them to open this website
Special String Again
You are viewing a single comment's thread. Return to all comments →
class point{ public: char key; long count; point(char key,long count){ this->key = key; this->count = count; } };
int main() { std::vector _v; long count = 1; int n; scanf("%d",&n); char str[n]; std::cin >> str; char ch = str[0];
}