本帖最后由 x_s_s_1 于 2020-1-15 10:50 编辑
按您的思路写了一个,请指正
 - ;;;带0前缀整数字符串相加
- (defun addIstr (str1 str2 / l1 l2 l)
- (setq str1 (mapcar 'read (mapcar 'chr (vl-string->list str1)))
- str2 (mapcar 'read (mapcar 'chr (vl-string->list str2)))
- l1 (length str1)
- l2 (length str2)
- l (max l1 l2)
- )
- (if (< l1 l)
- (repeat (- l l1) (setq str1 (cons 0 str1)))
- (repeat (- l l2) (setq str2 (cons 0 str2)))
- )
- (setq str1 (reverse (mapcar '+ str1 str2))
- str2 nil
- l 0
- )
- (foreach n str1
- (setq str2 (cons (rem (setq l (+ l n)) 10) str2)
- l (fix (/ l 10.))
- )
- )
- (if (= 1 l)
- (apply 'strcat (mapcar 'itoa (cons l str2)))
- (apply 'strcat (mapcar 'itoa str2))
- )
- )
|