fork download
#include <iostream>
#include <string>

// return  true if all characters ('0' or '1') in the range [x,y] are the same
bool is_same( const std::string& str, unsigned long x, unsigned long y )
{
    if( x > y || str.size() < (y-1) ) return false ;
    return ( str[x] == '0' || str[x] == '1' ) &&
            str.find_first_not_of( str[x], x ) > y ;
}

int main ()
{
    std::string str ;
    std::cout << "enter a string and press RETURN\n" ;
    std::getline( std::cin, str ) ; // 10110111111111111000111000001110001110001
    std::cout << "string: " << str << '\n' ;
    std::size_t x = 5 ;
    std::size_t y = 15 ;
    if( is_same( str, x, y ) ) std::cout << "Yes\n" ;
}
Success #stdin #stdout 0s 3032KB
stdin
10110111111111111000111000001110001110001
stdout
enter a string and press RETURN
string: 10110111111111111000111000001110001110001
Yes