-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathalphamirror.go
More file actions
50 lines (45 loc) · 937 Bytes
/
alphamirror.go
File metadata and controls
50 lines (45 loc) · 937 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
40
41
42
43
44
45
46
47
48
49
50
package main
import "os"
func main() {
if len(os.Args) != 2 {
return
}
lo := "abcdefghijklmnopqrstuvwxyz"
up := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
s := []rune(os.Args[1])
l := []rune(lo)
u := []rune(up)
for i := 0; i < len(s); i++ {
for j := 0; j < len(l); j++ {
if s[i] == l[j] {
s[i] = l[len(l)-1-j]
break
}
}
for j := 0; j < len(u); j++ {
if s[i] == u[j] {
s[i] = u[len(u)-1-j]
break
}
}
}
os.Stdout.WriteString(string(s) + "\n")
}
/**************** Another Way*****************/
// func main() {
// if len(os.Args) == 2 {
// args := []rune(os.Args[1])
// for i, ch := range args {
// if ch >= 'a' && ch <= 'z' {
// args[i] = 'z' - ch + 'a'
// }
// if ch >= 'A' && ch <= 'Z' {
// args[i] = 'Z' - ch + 'A'
// }
// }
// os.Stdout.WriteString(string(args))
// }
// os.Stdout.WriteString("\n")
// }
/********************************************/
// checkpoint