#include <iostream>
std::string removerepeatedDigits(std::string str) {
int len = str.length();
int i = 1, j = 1;
while (i < len) {
if (str[i] != str[i - 1]) {
str[j] = str[i];
j++;
i++;
}
// run to next not equal character
while (str[i] == str[i - 1]) {
i++;
}
}
str.resize(j);
return str;
}
int main()
{
std::string str = "951112722221333331";
str = removerepeatedDigits(str);
std::cout << str;
}
/*
run:
951272131
*/