-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheconom.go
99 lines (96 loc) · 2.08 KB
/
econom.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"bufio"
"container/list"
"fmt"
"os"
"strings"
"unicode"
)
func i_hate_parsing(s []string, index, countb int) (*list.List, int, int) {
parsed := list.New()
var c *list.List
if index >= len(s) {
return nil, index, countb
}
if s[index] == "(" {
k := countb
countb++
index++
c, index, countb = i_hate_parsing(s, index, countb)
parsed.PushBackList(c)
for countb != k {
c, index, countb = i_hate_parsing(s, index, countb)
if c != nil {
if c.Front().Value == "$" || c.Front().Value == "@" || c.Front().Value == "#" {
parsed.PushBack(c)
} else {
parsed.PushBackList(c)
}
}
}
return parsed, index, countb
} else if s[index] != ")" {
parsed.PushBack(s[index])
index++
c, index, countb = i_hate_parsing(s, index, countb)
if c != nil {
if c.Front().Value == "$" || c.Front().Value == "#" || c.Front().Value == "@" {
parsed.PushBack(c)
} else {
parsed.PushBackList(c)
}
} else {
return parsed, index, countb
}
} else {
countb--
index++
return nil, index, countb
}
return parsed, index, countb
}
func cal(tree *list.List) (string, []string) {
var set []string
var extr string
if unicode.IsLetter(rune(tree.Front().Value.(string)[0])) {
extr, _ = tree.Front().Value.(string)
return extr, nil
} else {
p := tree.Front().Next()
extr += tree.Front().Value.(string)
for p != nil {
switch p.Value.(type) {
case *list.List:
c, s := cal(p.Value.(*list.List))
extr += c
set = append(set, s...)
default:
c := p.Value.(string)
extr += c
}
p = p.Next()
}
set = append(set, extr)
}
return extr, set
}
func main() {
myscanner := bufio.NewScanner(os.Stdin)
myscanner.Scan()
line := myscanner.Text()
arline := strings.Split(line, "")
var newarline []string
for i := 0; i < len(arline); i++ {
if arline[i] != " " {
newarline = append(newarline, arline[i])
}
}
parsed, _, _ := i_hate_parsing(newarline, 0, 0)
_, nedoset := cal(parsed)
var normset = make(map[string]struct{})
for _, s := range nedoset {
normset[s] = struct{}{}
}
fmt.Println(len(normset))
}