-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path10789.go
75 lines (67 loc) · 1.08 KB
/
10789.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// UVa 10789 - Prime Frequency
package main
import (
"fmt"
"os"
)
func isPrime(n int) bool {
for i := 3; i*i <= n; i += 2 {
if n%i == 0 {
return false
}
}
return true
}
func primes() map[int]bool {
p := map[int]bool{2: true}
for i := 3; i < 2001; i += 2 {
if isPrime(i) {
p[i] = true
}
}
return p
}
func chars() []byte {
var c []byte
var i byte
for i = '0'; i <= '9'; i++ {
c = append(c, i)
}
for i = 'A'; i <= 'Z'; i++ {
c = append(c, i)
}
for i = 'a'; i <= 'z'; i++ {
c = append(c, i)
}
return c
}
func main() {
in, _ := os.Open("10789.in")
defer in.Close()
out, _ := os.Create("10789.out")
defer out.Close()
p := primes()
c := chars()
var t int
var line string
fmt.Fscanf(in, "%d", &t)
for i := 1; i <= t; i++ {
fmt.Fscanf(in, "%s", &line)
m := make(map[byte]int)
for j := range line {
m[line[j]]++
}
empty := true
fmt.Fprintf(out, "Case %d: ", i)
for _, v := range c {
if n, ok := m[v]; ok && p[n] {
empty = false
fmt.Fprintf(out, "%c", v)
}
}
if empty {
fmt.Fprint(out, "empty")
}
fmt.Fprintln(out)
}
}