这内存
我是晨曦,我喂自己袋盐!
宝塔可以跑起来![]()
@无名啊,你可以对它说请用中文回复。不过目前其他人已经插入了其他对话,所以你应该得不到上下文相关的回答。
要阅读本文,请使用谷歌浏览器翻译。
@老虎会游泳,怎么突然变成英文回复了。。。
层主 @老虎会游泳 于 2023-02-19 03:22 删除了该楼层。
层主 @老虎会游泳 于 2023-02-19 03:22 删除了该楼层。
@511,对
@老虎会游泳,cdn回源超时也会504吧
源站是在哪里,海外用国内cdn的确会这样,建议香港的节点中转下或者仅静态资源使用cdn
小米MIX2s(白)
@511,504表示cdn连不上你的服务器。问题也可能是cdn节点到你的服务器之间网络较差。
@无名啊,嗯,我的C++应用程序需要调用cgroup功能
@老虎会游泳,老虎这是深钻 Linux ?
@hik,品控差+1,再也不想碰了。我买的机械革命笔记本已经返修2次了,即将迎来第三次返修,早就有问题了,一直没空!!!
哈哈,机械革命Pro笔记本 rtx4060+12代标压i7只要5999,品控差,但价格香啊![]()
[email protected]
package main//计算hex校验和
import (
"bufio"
"fmt"
"os"
"regexp"
"strconv"
"strings"
)func main() {
fmt.Println("请输入要计算校验和的行:")
reader := bufio.NewReader(os.Stdin)
line, := reader.ReadString('\n')
line = strings.TrimSpace(line)
checksum, := strconv.ParseInt(line[len(line)-2:], 16, 64) //pattern := regexp.MustCompile(`.{2}`) parts := pattern.FindAllString(line[1:len(line)-2], -1) var nums []int for _, p := range parts { num, _ := strconv.ParseInt(p, 16, 64) nums = append(nums, int(num)) } newChecksum := 256 - reduce(nums) if checksum == int64(newChecksum) { fmt.Println("校验和匹配,该行无需修改") } else { fmt.Printf("校验和不匹配,原校验和:%d,应该改为:%d\n", checksum, newChecksum) fmt.Println("正确的行:") fmt.Printf("%s%02X\n", line[:len(line)-2], newChecksum) }
}
func reduce(nums []int) int {
return reduceHelper(nums, 0)
}
func reduceHelper(nums []int, acc int) int {
if len(nums) == 0 {
return acc % 256
}
return reduceHelper(nums[1:], (acc+nums[0])%256)
}This is a program written in Go to calculate the checksum of a given hex line and compare it to the last two digits of the input line. The program takes input from the user, removes whitespace characters, and extracts the last two digits as the expected checksum. Then, it extracts pairs of hex digits (two characters) from the remaining part of the input line and converts them to integers. The reduce function is called with the resulting list of integers as an argument, which recursively sums them and takes the result modulo 256. The calculated checksum is then compared to the expected checksum, and if they match, the program outputs that the line is correct. Otherwise, the program outputs the correct checksum and the modified line with the correct checksum appended at the end.
[email protected]
package main//计算hex校验和
import (
"bufio"
"fmt"
"os"
"regexp"
"strconv"
"strings"
)func main() {
fmt.Println("请输入要计算校验和的行:")
reader := bufio.NewReader(os.Stdin)
line, := reader.ReadString('\n')
line = strings.TrimSpace(line)
checksum, := strconv.ParseInt(line[len(line)-2:], 16, 64) //pattern := regexp.MustCompile(`.{2}`) parts := pattern.FindAllString(line[1:len(line)-2], -1) var nums []int for _, p := range parts { num, _ := strconv.ParseInt(p, 16, 64) nums = append(nums, int(num)) } newChecksum := 256 - reduce(nums) if checksum == int64(newChecksum) { fmt.Println("校验和匹配,该行无需修改") } else { fmt.Printf("校验和不匹配,原校验和:%d,应该改为:%d\n", checksum, newChecksum) fmt.Println("正确的行:") fmt.Printf("%s%02X\n", line[:len(line)-2], newChecksum) }
}
func reduce(nums []int) int {
return reduceHelper(nums, 0)
}
func reduceHelper(nums []int, acc int) int {
if len(nums) == 0 {
return acc % 256
}
return reduceHelper(nums[1:], (acc+nums[0])%256)
}
改下添加按任意键退出
Sure, you can modify the code to add a prompt for the user to press any key to exit the program. You can use the function to wait for the user to input any text before exiting the program. Here's an example:fmt.Scanln()go
Copy code
package mainimport (
"bufio"
"fmt"
"os"
"regexp"
"strconv"
"strings"
)func main() {
fmt.Println("请输入要计算校验和的行:")
reader := bufio.NewReader(os.Stdin)
line, := reader.ReadString('\n')
line = strings.TrimSpace(line)
checksum, := strconv.ParseInt(line[len(line)-2:], 16, 64)pattern := regexp.MustCompile(`.{2}`) parts := pattern.FindAllString(line[1:len(line)-2], -1) var nums []int for _, p := range parts { num, _ := strconv.ParseInt(p, 16, 64) nums = append(nums, int(num)) } newChecksum := 256 - reduce(nums) if checksum == int64(newChecksum) { fmt.Println("校验和匹配,该行无需修改") } else { fmt.Printf("校验和不匹配,原校验和:%d,应该改为:%d\n", checksum, newChecksum) fmt.Println("正确的行:") fmt.Printf("%s%02X\n", line[:len(line)-2], newChecksum) } fmt.Println("按任意键退出...") fmt.Scanln()
}
func reduce(nums []int) int {
return reduceHelper(nums, 0)
}func reduceHelper(nums []int, acc int) int {
if len(nums) == 0 {
return acc % 256
}
return reduceHelper(nums[1:], (acc+nums[0])%256)
}
With this modification, the program will wait for the user to press any key before exiting.[email protected]
fmt.Scanln()只能算是按回车键退出,不算是任意键退出
You are correct, waits for the user to input a complete line, which usually requires pressing the Enter key. If you want to wait for the user to press any key, you can use a platform-specific package like to read a single key without waiting for Enter to be pressed. Here's an example that uses this package to wait for the user to press any key:fmt.Scanln()github.com/eiannone/keyboardgo
Copy code
package mainimport (
"bufio"
"fmt"
"os"
"regexp"
"strconv"
"strings""github.com/eiannone/keyboard"
)
func main() {
fmt.Println("请输入要计算校验和的行:")
reader := bufio.NewReader(os.Stdin)
line, := reader.ReadString('\n')
line = strings.TrimSpace(line)
checksum, := strconv.ParseInt(line[len(line)-2:], 16, 64)pattern := regexp.MustCompile(`.{2}`) parts := pattern.FindAllString(line[1:len(line)-2], -1) var nums []int for _, p := range parts { num, _ := strconv.ParseInt(p, 16, 64) nums = append(nums, int(num)) } newChecksum := 256 - reduce(nums) if checksum == int64(newChecksum) { fmt.Println("校验和匹配,该行无需修改") } else { fmt.Printf("校验和不匹配,原校验和:%d,应该改为:%d\n", checksum, newChecksum) fmt.Println("正确的行:") fmt.Printf("%s%02X\n", line[:len(line)-2], newChecksum) } fmt.Println("按任意键退出...") keyboard.GetSingleKey()
}
func reduce(nums []int) int {
return reduceHelper(nums, 0)
}func reduceHelper(nums []int, acc int) int {
if len(nums) == 0 {
return acc % 256
}
return reduceHelper(nums[1:], (acc+nums[0])%256)
}
In this example, we use the function from the package to wait for the user to press any key before exiting. Note that this package may not work on all platforms, so you should check the documentation and test the program on the platforms you plan to use it on.GetSingleKey()github.com/eiannone/keyboard
一加8Pro
C:\Users\Admin\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
一加8Pro
@卷心菜,应该是1,我每次进去就输入wsl。
小米8(白)
计算机体系结构并没有原生的引用功能,只有原生的指针功能。所以在编译后的二进制程序里,所有引用操作都会被翻译为指针操作。
@胡椒舰长,map变量的值是指向存储map数据结构的内存地址。在C中,我们通常把这样的变量叫做指针变量。传递引用就是传递指针变量的值,也就是传递内存地址,也就是传递一个整数。
@老虎会游泳,为什么他第一句说
在赋值时,会复制一份指向底层数据结构的引用。如果你在一个函数中修改了 map,那么调用该函数的地方也会看到这个修改。
那这个引用类型和变量有啥区别,变量不也是在当前函数中可以看到改变