import scala collection mutable ArrayBuffer import scala util matching

 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
import scala.collection.mutable.ArrayBuffer
import scala.util.matching.Regex
import scala.io.Source
class Parse() {
def parsing(grammar:Array[String]) = grammar foreach {
gram => pattern findAllMatchIn gram foreach {
iterator => iterator.subgroups foreach splt
}
}
private def splt(str:String) = {
if (Character.isUpperCase(str.charAt(0))) str.split("") foreach { letter => result.append("<1, " + letter + ">" ) }
else result.append("<0, " + str + ">")
}
val result = new ArrayBuffer[String]()
private val pattern = new Regex("([0-9a-z]+)([A-Z]+)([0-9a-z]+)$")
}
object Main extends App {
val parser = new Parse
Source.fromFile("./src/input.txt").getLines() foreach {
line => parser.parsing(line.split("\\::="))
}
parser.result foreach println
}import scala.collection.mutable.ArrayBuffer
import scala.util.matching.Regex
import scala.io.Source
class Parse() {
def parsing(grammar:Array[String]) = grammar foreach {
gram => pattern findAllMatchIn gram foreach {
iterator => iterator.subgroups foreach splt
}
}
private def splt(str:String) = {
if (Character.isUpperCase(str.charAt(0))) str.split("") foreach { letter => result.append("<1, " + letter + ">" ) }
else result.append("<0, " + str + ">")
}
val result = new ArrayBuffer[String]()
private val pattern = new Regex("([0-9a-z]+)([A-Z]+)([0-9a-z]+)$")
}
object Main extends App {
val parser = new Parse
Source.fromFile("./src/input.txt").getLines() foreach {
line => parser.parsing(line.split("\\::="))
}
parser.result foreach println
}