当前位置:网站首页>go language study notes 2
go language study notes 2
2022-07-30 05:02:00 【N. LAWLIET】
Learn language with algorithms,
Go variable definitions can be
var s1 strings1 := "521"
Import and output need import "fmt"
fmt.Println("hello world")//Outputfmt.Scanf("%s%s", &s1, &s2)//input
The function uses func to define the parameter in front of the variable name, followed by the type, and the return value type is defined in front of the curly brackets
func test(s1 string, s2 string) int{return 1}
To get the length of the string, use strings.Count(str,"") to get it. The length should be reduced by one.
There is no char type in the go language, only the byte type, so a single character is of the byte type,
The array in the go language needs to initialize the length and cannot use variables, such as
var dp [10000][10000]int
That's all the language knowledge needed for the first algorithm problem,
Title: Given a string str and a string T, return the number of all substrings of str that contain all of T
Code
package mainimport ("fmt""math""strings")func main() {fmt.Println("hello world")var s1 stringvar s2 stringfmt.Scanf("%s%s", &s1, &s2)var ans int = findTsubString(s1, s2)fmt.Println("ans=", ans)//Findmain()strAns := getUniqueSubString("1232")fmt.Printf("strAns=%d", strAns)}func findTsubString(S string, T string) int {if strings.Count(S, "") < strings.Count(T, "") {return 0}N := strings.Count(S, "") - 1M := strings.Count(T, "") - 1var dp[10000][10000]intif S[0] == T[0] {dp[0][0] = 1}for index := 1; index < N; index++ {if S[index] == T[0] {dp[index][0] = dp[index-1][0] + 1} else {dp[index][0] = dp[index-1][0]}}for i := 1; i < N; i++ {for j := 1; j <= int(math.Min(float64(i), float64(M-1))); j++ {dp[i][j] = dp[i-1][j]if S[i] == T[j] {dp[i][j] += dp[i-1][j-1]}}}return dp[N-1][M-1]}
边栏推荐
- webService interface
- Catch That Cow(详解)
- 【周周有奖】云原生编程挑战赛“边缘容器”赛道邀你来战!
- VisualStudio2022本地调试进入特别慢问题解决
- WPF recursively obtains the list of specified control types in the form
- 软件测试员必看!数据库知识mysql查询语句大全
- Acwing完全数
- Unity3D Application simulation enters the front and background and pauses
- [Redis Master Cultivation Road] Jedis - the basic use of Jedis
- SVN 查看用户名密码
猜你喜欢
How to use labelme
webService interface
Xiamen SenseCore Technology MC3172(1): Introduction and Environment Construction
【Vitis】ZCU102开发板PS端控制PL端复位的代码实现
protobuf 中复合数据类型的读写
美国再次加息75个基点 陷入“技术性衰退”?加密市场却呈现复苏力量
Acwing完全数
(RCE) Remote Code/Command Execution Vulnerability Vulnerability Exercise
WPF introduces ttf icon file usage record
Classification of decision tree classification
随机推荐
LeetCode Algorithm 2326. 螺旋矩阵 IV
Simulation problem (below)
- B + tree index and MySQL series 】 【 what is the difference between a HASH index
[High Performance Computing] openMP
小程序使用npm包定制全局样式
Recursive Optimization of Fibonacci Sequences "Memo Recursion"
Seven, custom configuration
Alibaba Cloud's EasyNLP Chinese text image generation model takes you to become an artist in seconds
Requirements design document and the changing role of the product manager
DAY17, CSRF vulnerability
KubeMeet 报名 | 「边缘原生」线上技术沙龙完整议程公布!
Shanxi group (enterprises) in the second network security skills competition part problem WP (7)
22. Why do you need a message queue?What are the advantages of using the message queue?
Simulation Problem (Part 1)
Machine Learning: Knowing the Dimensionality Reduction Process Through Low Variance Filtering
[Android development] Splash interface / user agreement and privacy policy pop-up window / interface development
Classification of decision tree classification
WPF study notes "WPF Layout Basics"
解决go环境编译不了exe
(RCE) Remote Code/Command Execution Vulnerability Vulnerability Exercise