U E D R , A S I H C RSS

Reverse And Add/남상협

ReverseAndAdd/남상협

~cpp 
import unittest

class Palindrome:
    def Reverse(self,numbers):
        self.count=0
        self.mul=1
        self.stack=[]
        self.reverseNumber=0
        for i  in range(1,100):
            if numbers<=0:
                break
            else:
                self.stack.append(numbers%10)
                numbers=numbers/10
                self.count=self.count+1
        
        for i in range(1,self.count+1):
            self.reverseNumber=self.reverseNumber+self.stack.pop()*self.mul
            self.mul=self.mul*10
        return self.reverseNumber
    def run(self,numbers):        
        for i in range(0,101):
            self.Reverse(numbers)
            print numbers
            print self.reverseNumber
            print "------------"
            if numbers==self.reverseNumber:
                break
            else:
                numbers=numbers+self.Reverse(numbers)
        return i, self.reverseNumber

class testPalindrome(unittest.TestCase):
    def setUp(self):
        self.exPalindrome=Palindrome()
    def testReverse(self):
        self.assertEquals(951,self.exPalindrome.Reverse(159))
        self.assertEquals(265,self.exPalindrome.Reverse(562))
        self.assertEquals(57,self.exPalindrome.Reverse(750))
    def testRun(self):
        self.assertEquals((4,9339),self.exPalindrome.run(195))        
        self.assertEquals((5,45254),self.exPalindrome.run(265))
        self.assertEquals((3,6666),self.exPalindrome.run(750))                
if __name__=='__main__':
    unittest.main()
  • 엄청 허접하다 ㅠㅜ -상협
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:27:54
Processing time 0.0162 sec