Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang scheme
- (define (sum )
- (define in (open-input-file "input.txt"))
- (define out (open-output-file "out.txt" #:exists 'replace))
- (define (iter lst number n)
- (define ch (read-char in))
- (if (equal? ch eof) (begin (display (help (cons (+ (to-integer number 0 0) n)lst)) out) (close-output-port out))
- (cond
- ( (and (<= (char->integer ch) 57) (>= (char->integer ch) 48)) (iter lst (cons ch number) n))
- ( (equal? ch #\+) (iter lst '() (to-integer number 0 0)))
- ( (equal? ch #\newline) (iter lst '() 0))
- (else (iter (cons (+ (to-integer number 0 0) n) lst) '() 0)))))
- (iter '() '() 0))
- (define (to-integer lst n degree)
- (if (empty? lst) n
- (to-integer (cdr lst) (+ n (* (expt 10 degree) (-(char->integer(car lst)) 48))) (+ 1 degree))))
- (define (help lst)
- (sort (myfilter lst '()) >))
- (define (myfilter lst result)
- (if (empty? lst) result
- (if (pred (car lst) 0) (myfilter (cdr lst) (cons (car lst) result)) (myfilter (cdr lst) result))))
- (define (pred n i)
- (if (= n 0) true
- (if (>=(remainder n 10) i) (pred (quotient n 10) (remainder n 10)) false
- )))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement