[Codeforces] Unknown Language Round 1 F. Domain

Unknown Language Round 1 F. Domain

  • Time :
  • Space :
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
set channel {stdin}

gets $channel s

set len [string length $s]

set i 0
while {$i < $len} {
set c [string index $s $i]
if {! [string match {[0-9a-z.]} $c] } {
puts "NO"
exit
}
set i [expr $i + 1]
}

set i 0
while {$i + 1 < $len} {
set c1 [string index $s $i]
set c2 [string index $s [expr $i + 1]]
if {[string compare $c1 .] == 0 && [string compare $c2 .] == 0} {
puts "NO"
exit
}
set i [expr $i + 1]
}

set c [string index $s 0]
if {[string compare $c .] == 0} {
puts "NO"
exit
}

set c [string index $s [expr $len - 1]]
if {[string compare $c .] == 0} {
puts "NO"
exit
}

set i [expr $len - 1]
while {$i >= 0} {
set c [string index $s $i]
if {[string compare $c .] == 0} {
break
}
set i [expr $i - 1]
}

if {$i < 0} {
if {$len == 2 || $len == 3} {
puts "YES"
} else {
puts "NO"
}
} else {
if {$i == [expr $len - 3] || $i == [expr $len - 4]} {
puts "YES"
} else {
puts "NO"
}
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2023/12/27/PS/Codeforces/unknown-language-round-1-f/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.