Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define (rising? n)
- (define (iter n k)
- (if(zero? n)
- #t
- (if(< k (remainder n 10))
- #f
- (iter (quotient n 10) (remainder n 10)))))
- (iter (quotient n 10) (remainder n 10)))
- (define (sum1 file)
- (define in (open-input-file file))
- (define (next num sum lst)
- (define n (read-char in))
- (cond [(eq? n eof) (begin (close-input-port in) (if(rising? (+ num sum)) (write-to-file (sort (cons (+ num sum) lst) >)) (write-to-file (sort lst >))))]
- [(eq? n #\+) (next 0 num lst)]
- [(eq? n #\return) (begin (read-char in) (next 0 0 (if (rising? (+ num sum)) (cons (+ num sum) lst) lst)))]
- [else (next (+ (* 10 num) (- (char->integer n) 48)) sum lst)]))
- (next 0 0 null))
- (define (write-to-file lst)
- (define out (open-output-file "output.txt" #:exists 'replace))
- (define (iter lst)
- (if(null? lst)
- (close-output-port out)
- (begin (display (car lst) out) (display "\r\n" out) (iter (cdr lst)))))
- (iter lst))
- #lang scheme
- (define (read-graph filename)
- (define (read-vertex)
- (define n (read in))
- (foldl (lambda (i lst)
- (if (= i n) lst
- (cons (read in) lst)))
- '()
- (build-list n values)))
- (define in (open-input-file filename))
- (define n (read in))
- (reverse
- (foldl (lambda (i lst)
- (if (= i n) lst
- (cons (read-vertex) lst)))
- '()
- (build-list n values))))
- ;4
- ; 3 1 2 3 - 0 (1 2 3) (0 2 3) (0 1 3) (0 1 2)
- ; 3 0 2 3 1
- ; 3 0 1 3 2
- ; 3 0 1 2 3
- ;в каждом проверить member ДО k-1
- ;2
- (define (Sol2 filename)
- (define k (read (open-input-file filename)))
- (define filelst (read-graph filename))
- (define (searching lest)
- (if (empty? lest) #t
- (if (= (length (car lest)) (- k 1)) (searching (cdr lest)) #f)))
- (searching filelst))
- (define (my-cdar lst)
- (if (= (length lst) 1) (cdr lst)
- (cons (cdar lst) (cdr lst))))
- (define (Sol3 filename)
- (define out (open-output-file "output.txt" #:exists 'replace))
- (define filelst (read-graph filename))
- (define r (read (open-input-file filename)))
- (define (creating k lest rez)
- (if (empty? lest) rez
- (if (empty? (car lest)) (creating (add1 k) (cdr lest) rez)
- (if (= (length (car lest)) 1) (creating (add1 k) (cdr lest) (cons (cons k (caar lest)) rez))
- (creating k (my-cdar lest) (cons (cons k (caar lest)) rez)) ))))
- (define result (creating 0 filelst (cons (cons (- (length filelst) 1) (car (reverse (car (reverse filelst))))) '())))
- (define (outting file rez)
- (if (empty? rez) (close-output-port file)
- (begin (display (car rez) file)
- (write-char #\newline file )
- (write-char #\return file)
- (outting file (cdr rez))
- )))
- (outting out result))
- (define (Sol1 filename)
- (define filelst (read-graph filename))
- (define (searching k lst)
- (if (empty? lst) k
- (if (empty? (car lst)) (searching (add1 k) (cdr lst))
- (searching k (cdr lst)))))
- (searching 0 filelst))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement