forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathF.kt
More file actions
39 lines (32 loc) · 881 Bytes
/
F.kt
File metadata and controls
39 lines (32 loc) · 881 Bytes
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
import java.util.*
fun main(args: Array<String>) {
var s = readLine()!!
// not start & end with spaces
s = s.replace(Regex("^ +"), "")
s = s.replace(Regex(" +$"), "")
// no 2 consecutive spaces
s = s.replace(Regex(" +"), " ")
s = s.toLowerCase()
// comma
s = s.replace(Regex(" *, *"), ", ")
// dot
s = s.replace(Regex(" *\\. *"), ". ")
s = s.replace(Regex("^ +"), "")
s = s.replace(Regex(" +$"), "")
val n = s.length
var dot = false
for (i in 0..n-1) {
val c = s[i]
if (c != ' ' && c != '.' && c != ',') {
if (i == 0 || dot) {
print(c.toUpperCase())
dot = false
}
else print(c)
} else {
if (c == '.') dot = true
print(c)
}
}
println("")
}