-
Notifications
You must be signed in to change notification settings - Fork 0
/
1157.scm
44 lines (44 loc) · 2.66 KB
/
1157.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(define (find-max-char lst)
(let ((max-value (apply max lst)))
(do ((lst lst (cdr lst))
(acc '() acc)
(n 0 (+ n 1))
(isambiguses #f isambiguses))
((null? lst) (if isambiguses
(print "?")
(print (integer->char (+ (car acc) (char->integer #\A))))))
(if (= max-value (car lst))
(if (null? acc)
(set! acc (cons n acc))
(set! isambiguses #t))))))
(let ((alpha-list (make-vector 26 0)))
(do ((alpha-list alpha-list alpha-list)
(c (read-char) (read-char)))
((eof-object? c) (find-max-char (vector->list alpha-list)))
(case c
((#\a #\A) (vector-set! alpha-list 0 (+ 1 (vector-ref alpha-list 0))))
((#\b #\B) (vector-set! alpha-list 1 (+ 1 (vector-ref alpha-list 1))))
((#\c #\C) (vector-set! alpha-list 2 (+ 1 (vector-ref alpha-list 2))))
((#\d #\D) (vector-set! alpha-list 3 (+ 1 (vector-ref alpha-list 3))))
((#\e #\E) (vector-set! alpha-list 4 (+ 1 (vector-ref alpha-list 4))))
((#\f #\F) (vector-set! alpha-list 5 (+ 1 (vector-ref alpha-list 5))))
((#\g #\G) (vector-set! alpha-list 6 (+ 1 (vector-ref alpha-list 6))))
((#\h #\H) (vector-set! alpha-list 7 (+ 1 (vector-ref alpha-list 7))))
((#\i #\I) (vector-set! alpha-list 8 (+ 1 (vector-ref alpha-list 8))))
((#\j #\J) (vector-set! alpha-list 9 (+ 1 (vector-ref alpha-list 9))))
((#\k #\K) (vector-set! alpha-list 10 (+ 1 (vector-ref alpha-list 10))))
((#\l #\L) (vector-set! alpha-list 11 (+ 1 (vector-ref alpha-list 11))))
((#\m #\M) (vector-set! alpha-list 12 (+ 1 (vector-ref alpha-list 12))))
((#\n #\N) (vector-set! alpha-list 13 (+ 1 (vector-ref alpha-list 13))))
((#\o #\O) (vector-set! alpha-list 14 (+ 1 (vector-ref alpha-list 14))))
((#\p #\P) (vector-set! alpha-list 15 (+ 1 (vector-ref alpha-list 15))))
((#\q #\Q) (vector-set! alpha-list 16 (+ 1 (vector-ref alpha-list 16))))
((#\r #\R) (vector-set! alpha-list 17 (+ 1 (vector-ref alpha-list 17))))
((#\s #\S) (vector-set! alpha-list 18 (+ 1 (vector-ref alpha-list 18))))
((#\t #\T) (vector-set! alpha-list 19 (+ 1 (vector-ref alpha-list 19))))
((#\u #\U) (vector-set! alpha-list 20 (+ 1 (vector-ref alpha-list 20))))
((#\v #\V) (vector-set! alpha-list 21 (+ 1 (vector-ref alpha-list 21))))
((#\w #\W) (vector-set! alpha-list 22 (+ 1 (vector-ref alpha-list 22))))
((#\x #\X) (vector-set! alpha-list 23 (+ 1 (vector-ref alpha-list 23))))
((#\y #\Y) (vector-set! alpha-list 24 (+ 1 (vector-ref alpha-list 24))))
((#\z #\Z) (vector-set! alpha-list 25 (+ 1 (vector-ref alpha-list 25)))))))