How to find out all palindromic numbers

后端 未结 8 1809
独厮守ぢ
独厮守ぢ 2020-12-14 12:05

A palindromic number or numeral palindrome is a \"symmetrical\" number like 16461, that remains the same when its digits are reversed.

The term palindromic is derive

8条回答
  •  囚心锁ツ
    2020-12-14 12:47

    import Queue
    import copy
    
    def printPalindromesTillK(K):
        q = Queue.Queue(K);
        for i in range(0, 10):
            q.put(str(i));
            q.put(str(i) + str(i));
        while(not q.empty()):
            elem = q.get();
            print  elem;
            for i in range(1, 10):
                item = str(i) + elem + str(i);
                if int(item) <= K:
                   q.put(item); 
    
    print printPalindromesTillK(10000);
    

提交回复
热议问题