Today is the second week of waiting to be scooped up, and the interview process has not made any progress. Fortunately, I had the opportunity to write a written test this month, and with the mentality of feeling the atmosphere for the first time, I went to brush the music buckle at the last minute. Did not expect to try to die zZ🥶
The written test profile
The first question
During the war, army A often intercepted intelligence documents sent by Army B, and the contents of these intelligence documents were added.
In order to break the intelligence content, the intelligence team of ARMY A found that the intelligence of Army B had the following rules after A lot of research and analysis
1. The letters in the information contain only capital letters. Each letter (AZ) may represent another letter.
2. Every number (0-9) in intelligence may represent another number
3. Characters other than letters and numbers in information will not change
4. Alphabetical order as follows: ABCDEFGHIJKLMNOPQRSTUVWXYZ
The order of A is 1, the order of B is 2, the order of C is 3
5. The deciphering method of intelligence is closely related to the first character X of intelligence
– If x is a letter, all letters and numbers in the information will be pushed back in alphabetical order. If the first character is B and the alphabetical order is second, all letters and numbers in the information are two bits later.
If x is a number, all letters and numbers in the information are backward. For example, if the first character is 3, all letters and numbers in the information must be followed by 3 digits.
If x is any other character, it is equivalent to x being A. (i.e., move back 1 bit)
6. If you move x bits back in the process of replacing letters, the system returns to A to start the calculation. If the letter Z is backward one bit, the corresponding letter is A. The letter Z is three digits backward, corresponding to the letter C.
7. If in the process of replacing a number, you move backwards by x and exceed the number 9, you return to the beginning of the calculation. For example, if the number 9 is backed by one digit, the corresponding digit is 0. If the number 8 is backed by three digits, the corresponding digit is 1
As the chief intelligence officer of army A, can you write A program to automatically complete the decoding of intelligence?
Input and Output Example Sample â‘ Input: xy.0a Output: Vw.4y
Sample â‘¡ input:.4am output:.5BN
Their thinking
Seeing such a long question, the dyslexic first shuts down. But although the question is long, take a long time to read from beginning to end, always understand the question, should be examining ASCII code shift conversion. The difficulty of the questions is general, but the workload is very large. After all, there are various boundary values to consider.
If the first character is an uppercase letter or number, return ASCII, otherwise else; We then get the ASCII for the first character, enter the for loop, and iterate over STR; If the current character is a digit, numeric ASCII shift is performed; if the current character is a letter, alphabetic ASCII shift is performed; if neither character is a digit, no shift is performed.
code
package main
import (
"fmt"
)
//A-Z :ASCII VALUE 65-90
//0-9 :ASCII VALUE 48-57
func main(a) {
str := ""
fmt.Scan(&str)
a := ""
rdata := []rune(a)
if IsDigit(rune(str[0])) || IsLetter(rune(str[0])) {
fval := GetValue(string(str[0]))
inx := int(fval[0])
for _, item := range str {
if IsDigit(item) {
c := DigitRemove(item, inx)
rdata = append(rdata, c)
} else if IsLetter(item) {
c := LetterRemove(item, inx)
rdata = append(rdata, c)
} else {
rdata = append(rdata, item)
}
}
} else {
for _, item := range str {
c := OtherRemove(item)
rdata = append(rdata, c)
}
}
fmt.Println(string(rdata))
}
func GetValue(data string) []rune {
digit := []string{"0"."1"."2"."3"."4"."5"."6"."Seven"."8"."9"}
for _, item := range digit {
if data == item {
return []rune(item)
}
}letter := []string{
"A"."B"."C"."D"."E"."F"."G"."H"."I"."J"."K"."L"."M"."N"."O"."P"."Q"."R"."S"."T"."U"."V"."W"."X"."Y"."Z"}
for _, item := range letter {
if data == item {
return []rune(item)
}
}
return nil
}
func IsDigit(data rune) bool {
digit := []string{"0"."1"."2"."3"."4"."5"."6"."Seven"."8"."9"}
for _, item := range digit {
if string(data) == item {
return true}}return false
}
func IsLetter(data rune) bool {
letter := []string{
"A"."B"."C"."D"."E"."F"."G"."H"."I"."J"."K"."L"."M"."N"."O"."P"."Q"."R"."S"."T"."U"."V"."W"."X"."Y"."Z"}
for _, item := range letter {
if string(data) == item {
return true}}return false
}
func DigitRemove(data rune, dip int) rune {
if dip >= 48 && dip <= 57 {
dis := dip - 48
if data+rune(dis) > 57 {
temp := data + rune(dis) - 57
data = temp + 48
return data
} else {
data = data + rune(dis)
return data
}
}
if dip >= 65 && dip <= 90 {
dis := dip - 65 + 1
if data+rune(dis) > 57 {
temp := data + rune(dis) - 57
a := temp % 10
data = rune(a + 48 - 1)
return data
} else {
data = data + rune(dis)
return data
}
}
return data
}
func LetterRemove(data rune, dip int) rune {
if dip >= 48 && dip <= 57 {
dis := dip - 48
if data+rune(dis) > 90 {
temp := data + rune(dis) - 90
data = temp + 65
return data
} else {
data = data + rune(dis)
return data
}
}
if dip >= 65 && dip <= 90 {
dis := dip - 65 + 1
if data+rune(dis) > 90 {
temp := data + rune(dis) - 90
data = temp + 65 - 1
return data
} else {
data = data + rune(dis)
return data
}
}
return data
}
func OtherRemove(data rune) rune {
if data > 90 || data < 65 && data > 57 || data < 48 {
return data
}
if data+1 > 90 {
temp := data + 1 - 90
data = temp + 65
return data
} else if data+1 > 65 && data+1 < 90 || data+1 > 48 && data+1 < 57 {
data = data + 1
return data
} else {
temp := data + 1 - 57
data := temp + 48
return data
}
Copy the code
After writing feeling this is not like writing algorithm more like writing business, panic at that time a P can think of only press the liver out, so a stupid B writing method. (Really want to know what easy way, big guy 99 me
So much for today, update the next topic
Give us a preview of the title
In problem two, enter two strings A and b
Return the number of substrings containing the first m characters of string A and the first n characters of string B, and return the final result.
I/O example
ab ac
1 1
1