-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path10093.go
57 lines (51 loc) · 871 Bytes
/
10093.go
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
45
46
47
48
49
50
51
52
53
54
55
56
57
// UVa 10093 - An Easy Problem!
package main
import (
"fmt"
"os"
)
func number(c byte) int {
switch {
case c >= '0' && c <= '9':
return int(c - '0')
case c >= 'A' && c <= 'Z':
return int(10 + c - 'A')
case c >= 'a' && c <= 'z':
return int(36 + c - 'a')
default:
return 0
}
}
func solve(line string) int {
var sum, max int
for i := range line {
num := number(line[i])
sum += num
if num > max {
max = num
}
}
for i := max; i <= 62; i++ {
if sum%i == 0 {
return i + 1
}
}
return 0
}
func main() {
in, _ := os.Open("10093.in")
defer in.Close()
out, _ := os.Create("10093.out")
defer out.Close()
var line string
for {
if _, err := fmt.Fscanf(in, "%s", &line); err != nil {
break
}
if base := solve(line); base == 0 {
fmt.Fprintln(out, "such number is impossible!")
} else {
fmt.Fprintln(out, base)
}
}
}