How to check if a number is a repdigit number (a natural number composed of repeated digits) in C++

1 Answer

0 votes
#include <iostream>
#include <string>
#include <set>

bool isRepdigitNumber(int num) {
    std::string str = std::to_string(num);
         
    std::set<char> st(str.begin(), str.end());
          
    return st.size() == 1;
}

int main()
{
    int num = 8888888;
   
    if (isRepdigitNumber(num)) {
        std::cout << "yes";
    } else {
        std::cout << "no";
    }
}


 
/*
run:
 
yes
 
*/

 



answered Feb 7, 2024 by avibootz
...