当前位置: 首页 > news >正文

学习Rust的第三天:猜谜游戏

基于Steve Klabnik的《The Rust Programming Language》一书。今天我们在rust中建立一个猜谜游戏。

Introduction 介绍

We will build a game that will pick a random number between 1 to 100 and the user has to guess the number on a correct guess the user wins.
我们将构建一个游戏,它将选择1到100之间的随机数字,用户必须猜测正确的猜测用户获胜的数字。

Algorithm 算法

This is what the pseudo code would look like
这就是伪代码的样子

secret_number = (Generate a random number)
loop {Write “Please input your guess”Read guessWrite "Your guess : ${guess}"if(guess > secret_number){Write "Too high!"}else if(guess < secret_number){Write "Too low!"}else if(guess==number){Write "You win"break}
}

Step 1 : Set up a new project
步骤1:创建一个新项目

Use the cargo new command to set up a project
使用 cargo new 命令设置项目

$ cargo new guessing_game
$ cd guessing_game

Step 2 : Declaring variables and reading user input
步骤2:声明变量并阅读用户输入

Filename : main.rs Film:main.rs

use std::io;fn main() {println!("Guess the number");println!("Please input your guess");let mut guess = String::new();io::stdin().read_line(&mut guess).expect("Failed to read line");println!("Your guess: {}", guess);
}

Let’s break the code down line by line :
让我们逐行分解代码:

  • use std::io; This line brings the std::io (standard input/output) library into scope. The std::io library provides a number of useful features for handling input/output.
    use std::io; 此行将 std::io (标准输入/输出)库带入范围。 std::io 库提供了许多用于处理输入/输出的有用特性。
  • fn main(){...} This is the main function where the program execution begins.
    fn main(){...} 这是程序开始执行的main函数。
  • println!("Guess the number"); println! is a macro that prints the text to the console.
    println!("Guess the number"); println! 是一个宏,它将文本打印到控制台。
  • println!("Please input your guess"); This line prompts the user to enter their guess.
    println!("Please input your guess"); 这一行提示用户输入他们的猜测。
  • let mut guess = String::new(); This line declares a mutable variable guess and initializes it to an empty string. *mut means the variable is mutable*, i.e., its value can be changed. String::new() creates a new, empty string.
    let mut guess = String::new(); 这一行声明了一个可变变量 guess ,并将其转换为空字符串。 *mut 表示变量是可变的 *,即,其值可以改变。 String::new() 创建一个新的空字符串。
  • io::stdin().read_line(&mut guess).expect("Failed to read line"); This line reads the user input from the standard input (keyboard). The entered input is put into the guess string. If this process fails, the program will stop execution and display the message "Failed to read line".
    io::stdin().read_line(&mut guess).expect("Failed to read line"); 这一行从标准输入(键盘)读取用户输入。输入的输入被放入 guess 字符串中。如果此过程失败,程序将停止执行,并显示消息“读取行失败”。
  • println!("Your guess : {guess}"); This line prints out the string "Your guess: ", followed by whatever the user inputted.
    println!("Your guess : {guess}"); 这一行打印出字符串“Your guess:“,后跟用户输入的任何内容。

Step 3 : Generating a random number
步骤3:生成随机数

The number should be different each time for replayability. Rust’s standard library doesn’t include random number functionality, but the Rust team provides a rand crate for this purpose.
为了可重玩性,每次的数字应该不同。Rust的标准库不包含随机数功能,但Rust团队为此提供了一个 rand crate。

A Rust crate is like a neatly packaged box of code that you can easily use and share with others in the Rust programming language.
Rust crate就像一个整齐打包的代码盒,您可以轻松使用Rust编程语言并与其他人共享。

To use the rand crate :
使用 rand crate:

Filename: Cargo.toml Filtrate:Cargo.toml

[package]
name = "guessing_game"
version = "0.1.0"
edition = "2021"[dependencies]
rand = "0.8.5"  #append this line

Understanding the Cargo.toml file :
了解 Cargo.toml 文件:

  1. [package] [包]
  • name = "guessing_game": The name of the Rust package (or crate) is set to "guessing_game".
    name = "guessing_game" :Rust包(或crate)的名称设置为“guessing_game”。
  • version = "0.1.0": The version of the crate is specified as "0.1.0".
    version = "0.1.0" :机箱的版本指定为“0.1.0”。
  • edition = "2021": Specifies the Rust edition to use (in this case, the 2021 edition).
    edition = "2021" :指定要使用的Rust版本(在本例中为2021版)。

2. [dependencies] 2. [依赖关系]

  • rand = "0.8.5": Adds a dependency on the "rand" crate with version "0.8.5". This means the "guessing_game" crate relies on the functionality provided by the "rand" crate, and version 0.8.5 specifically.
    rand = "0.8.5" :在版本为“0.8.5”的“兰德”crate上添加依赖项。这意味着“guessing_game”crate依赖于“兰德”crate提供的功能,特别是0.8.5版本。

In simpler terms, this configuration file (Cargo.toml) is like a recipe for your Rust project, specifying its name, version, Rust edition, and any external dependencies it needs (in this case, the "rand" crate).
简单地说,这个配置文件( Cargo.toml )就像是Rust项目的配方,指定了它的名称、版本、Rust版本以及它需要的任何外部依赖(在本例中是“兰德”crate)。

After this without changing any code run cargo build , Why do we do that?
在此之后,不改变任何代码运行 cargo build ,为什么我们这样做?

  • Fetch Dependencies: cargo build fetches and updates the project's dependencies specified in Cargo.toml.
    获取依赖项: cargo build 获取并更新 Cargo.toml 中指定的项目依赖项。
  • Dependency Resolution: It resolves and ensures the correct versions of dependencies are installed.
    依赖项解析:它解析并确保安装了正确版本的依赖项。
  • Build Process: Compiles Rust code and dependencies into executable artifacts or libraries.
    构建过程:将Rust代码和依赖项编译为可执行工件或库。
  • Check for Errors: Identifies and reports compilation errors, ensuring code consistency.
    检查错误:检查并报告编译错误,确保代码一致性。
  • Update lock file: Updates the Cargo.lock file to record the exact dependency versions for reproducibility.
    更新锁定文件:更新 Cargo.lock 文件以记录精确的依赖性版本,以实现再现性。

Now let’s talk code 现在我们来谈谈代码

use std::io;
use rand::Rng;fn main() {println!("Guess the number!");let secret_number = rand::thread_rng().gen_range(1..=100);println!("Secret number: {}", secret_number);println!("Please input your guess");let mut guess = String::new();io::stdin().read_line(&mut guess).expect("Failed to read line");println!("Your guess: {}", guess);
}

Running the program : 运行程序:

$ cargo run
Guess the number!
Secret number : 69
Please input your guess
32
Your guess : 32

Let’s see what we did here :
让我们看看我们在这里做了什么:

  • use rand::Rng; : This line is an import statement that brings the Rng trait into scope, allowing you to use its methods.
    use rand::Rng; :这一行是一个import语句,它将 Rng trait带入作用域,允许你使用它的方法。
  • rand::thread_rng(): This part initializes a random number generator specific to the current thread. The rand::thread_rng() function returns a type that implements the Rng trait.
    rand::thread_rng() :这部分提供了一个特定于当前线程的随机数生成器。 rand::thread_rng() 函数返回一个实现了 Rng trait的类型。
  • .gen_range(1..=100): Using the random number generator (Rng trait), this code calls the gen_range method to generate a random number within a specified range. The range is defined as 1..=100, meaning the generated number should be between 1 and 100 (inclusive).
    .gen_range(1..=100) :使用随机数生成器( Rng trait),这段代码调用 gen_range 方法来生成指定范围内的随机数。范围被定义为 1..=100 ,这意味着生成的数字应该在1和100之间(包括1和100)。

Step 4 : Comparing the guess to the user input
步骤4:将猜测与用户输入进行比较

Now that we have the input, the program compares the user’s guess to the secret number to determine if they guessed correctly. If the guess matches the secret number, the user is successful; otherwise, the program evaluates whether the guess is too high or too low.
现在我们有了输入,程序将用户的猜测与秘密数字进行比较,以确定他们是否猜对了。如果猜测与秘密数字匹配,则用户成功;否则,程序评估猜测是否过高或过低。

Let’s take a look at the code and then break it down :
让我们看看代码,然后分解它:

use std::io;
use std::cmp::Ordering;
use rand::Rng;fn main() {println!("Guess the number!");let secret_number = rand::thread_rng().gen_range(1..=100);println!("Secret number: {}", secret_number);println!("Please input your guess");let mut guess = String::new();io::stdin().read_line(&mut guess).expect("Failed to read line");let guess: u32 = guess.trim().parse().expect("Please type a number!");println!("Your guess: {}", guess);match guess.cmp(&secret_number) {Ordering::Less => println!("Too small!"),Ordering::Greater => println!("Too big!"),Ordering::Equal => println!("You win!"),}
}

Running the program : 运行程序:

$ cargo run
Guess the number!
Secret number : 48
Please input your guess
98
Your guess : 98
Too big!

Explanation : 说明:

  • let guess: u32 = guess.trim().parse().expect("Please type a number!");: Shadowing the variable guess, it parses the string into an unsigned 32-bit integer. If parsing fails, it prints an error message.
    let guess: u32 = guess.trim().parse().expect("Please type a number!"); :隐藏变量 guess ,将字符串解析为无符号32位整数。如果解析失败,它将打印一条错误消息。
  • match guess.cmp(&secret_number) { ... }: Compares the user's guess to the secret number using a match statement, handling three cases: less than, greater than, or equal to the secret number.
    第0号:使用 match 语句将用户的猜测与秘密数字进行比较,处理三种情况:小于、大于或等于秘密数字。

Shadowing: 阴影:

  • Shadowing is when a new variable is declared with the same name as an existing variable, effectively “shadowing” the previous one.
    隐藏是当一个新变量与现有变量同名时,有效地“隐藏”前一个变量。
  • In this code, let guess: u32 = ... is an example of shadowing. The second guess shadows the first one, changing its type from String to u32. Shadowing is often used to reassign a variable with a new value and type while keeping the same name.
    在这段代码中, let guess: u32 = ... 是阴影的一个例子。第二个 guess 隐藏第一个,将其类型从 String 更改为 u32 。隐藏通常用于为变量重新分配新的值和类型,同时保持名称不变。

Step 5 : Looping the guesses till the user wins
第5步:循环猜测,直到用户获胜

In Step 5, the program implements a loop structure to repeatedly prompt the user for guesses until they correctly guess the secret number as we saw in the algorithm
在步骤5中,程序实现了一个循环结构,反复提示用户进行猜测,直到他们正确地猜出密码,就像我们在算法中看到的那样

As always code then explanation :
一如既往的代码然后解释:

use std::io;
use std::cmp::Ordering;
use rand::Rng;fn main() {println!("Guess the number!");let secret_number = rand::thread_rng().gen_range(1..=100);println!("Secret number: {}", secret_number);loop {println!("Please input your guess");let mut guess = String::new();io::stdin().read_line(&mut guess).expect("Failed to read line");let guess: u32 = guess.trim().parse().expect("Please type a number!");println!("Your guess: {}", guess);match guess.cmp(&secret_number) {Ordering::Less => println!("Too small!"),Ordering::Greater => println!("Too big!"),Ordering::Equal => {println!("You win!");break;},}}
}

Running the program: 运行程序:

$ cargo run
Guess the number!
Secret number : 23
Please input your guess
4
Your guess : 4
Too small!
Please input your guess
76
Your guess : 76
Too big!
Please input your guess
23
Your guess : 4
You win!

Explanation: 说明:

  • loop{...} statement is used to create an infinite loop
    loop{...} 语句用于创建无限循环
  • We are using the break statement to exit out of the program when the variables guess and secret_number are the same.
    当变量 guess 和 secret_number 相同时,我们使用 break 语句退出程序。

Step 6 : Handling invalid input
步骤6:处理无效输入

In Step 6, we want to handle invalid inputs and errors because of them. For example : entering a string in the prompt
在第6步中,我们要处理无效输入和由此产生的错误。例如:在提示符中输入字符串

use std::io;
use std::cmp::Ordering;
use rand::Rng;fn main() {println!("Guess the number!");let secret_number = rand::thread_rng().gen_range(1..=100);println!("Secret number: {}", secret_number);loop {println!("Please input your guess");let mut guess = String::new();io::stdin().read_line(&mut guess).expect("Failed to read line");let guess: u32 = match guess.trim().parse() {Ok(num) => num,Err(_) => continue,};println!("Your guess: {}", guess);match guess.cmp(&secret_number) {Ordering::Less => println!("Too small!"),Ordering::Greater => println!("Too big!"),Ordering::Equal => {println!("You win!");break;},}}
}

Running the program: 运行程序:

$ cargo run
Guess the number!
Secret number : 98
Please input your guess
meow
Please input your guess
43
Your guess : 43
Too small!

Parse User Input: 解析用户输入:

  • Attempts to parse the string in guess into an unsigned 32-bit integer.
    尝试将 guess 中的字符串解析为无符号32位整数。
  • Uses the trim method to remove leading and trailing whitespaces from the user's input.
    使用 trim 方法从用户输入中删除前导和尾随空格。

Match Statement: 匹配声明:

  • The match statement checks the result of the parsing operation.
    match 语句检查解析操作的结果。
  • Ok(num) => num: If parsing is successful, assigns the parsed number to the variable guess.
    Ok(num) => num :如果解析成功,将解析后的数字赋给变量 guess 。

Error Handling: 错误处理:

  • Err(_) => continue: If an error occurs during parsing, the placeholder '_' matches any error, and the code inside the loop continues, prompting the user for input again.
    第0号:如果在解析过程中出现错误,占位符'_'将匹配任何错误,循环中的代码将继续执行,提示用户再次输入。

Summary 总结

In this article, we embarked on our third day of learning Rust by building a guessing game. Here’s a summary of the key steps and concepts covered:Introduction
在本文中,我们通过构建一个猜谜游戏开始了学习Rust的第三天。以下是所涵盖的关键步骤和概念的摘要:简介

  • The goal is to create a game where the user guesses a randomly generated number between 1 and 100.
    我们的目标是创建一个游戏,让用户猜测1到100之间随机生成的数字。

Algorithm 算法

  • A generic algorithm was outlined, providing a high-level overview of the game’s logic.
    概述了一个通用算法,提供了游戏逻辑的高级概述。

Step 1: Set up a new project
步骤1:创建一个新项目

  • Used cargo new to create a new Rust project named "guessing_game."
    使用 cargo new 创建一个名为“guessing_game”的新Rust项目。“

Step 2: Declaring variables and reading user input
步骤2:声明变量并阅读用户输入

  • Introduced basic input/output functionality using std::io.
    使用 std::io 引入基本输入/输出功能。
  • Demonstrated reading user input, initializing variables, and printing messages.
    演示了阅读用户输入、初始化变量和打印消息。

Step 3: Generating a random number
步骤3:生成随机数

  • Added the rand crate as a dependency to generate random numbers.
    添加了 rand crate作为依赖项来生成随机数。
  • Used rand::thread_rng().gen_range(1..=100) to generate a random number between 1 and 100.
    使用 rand::thread_rng().gen_range(1..=100) 生成1到100之间的随机数。

Step 4: Comparing the guess to the user input
步骤4:将猜测与用户输入进行比较

  • Introduced variable shadowing and compared user input to the secret number.
    引入了变量跟踪,并将用户输入与秘密数字进行比较。
  • Used a match statement to handle different comparison outcomes.
    使用 match 语句处理不同的比较结果。

Step 5: Looping the guesses till the user wins
第5步:循环猜测,直到用户获胜

  • Implemented a loop structure to allow the user to make repeated guesses until they correctly guess the secret number.
    实现了一个循环结构,允许用户重复猜测,直到他们正确地猜测秘密数字。

Step 6: Handling invalid input
步骤6:处理无效输入

  • Addressed potential errors by adding error handling to the user input parsing process.
    通过向用户输入分析过程添加错误处理来解决潜在错误。
  • Used the continue statement to skip the current iteration and prompt the user again in case of an error.
    使用 continue 语句跳过当前迭代,并在出现错误时再次提示用户。

Final code : 最终代码:

use std::io;
use std::cmp::Ordering;
use rand::Rng;fn main() {println!("Guess the number!");let secret_number = rand::thread_rng().gen_range(1..=100);loop {println!("Please input your guess");let mut guess = String::new();io::stdin().read_line(&mut guess).expect("Failed to read line");let guess: u32 = match guess.trim().parse() {Ok(num) => num,Err(_) => continue,};println!("Your guess: {}", guess);match guess.cmp(&secret_number) {Ordering::Less => println!("Too small!"),Ordering::Greater => println!("Too big!"),Ordering::Equal => {println!("You win!");break;},}}
}

相关文章:

学习Rust的第三天:猜谜游戏

基于Steve Klabnik的《The Rust Programming Language》一书。今天我们在rust中建立一个猜谜游戏。 Introduction 介绍 We will build a game that will pick a random number between 1 to 100 and the user has to guess the number on a correct guess the user wins. 我们将…...

React中子传父的方式及原理

方式挺多的&#xff0c;先说最常用的通过props进行父子组件的数据传递和修改以及原理 在React中&#xff0c;props不仅用于传递数据&#xff0c;它们也可以传递可以执行的函数&#xff0c;这使得子组件能够间接更新父组件的状态。这种方法强化了React的单向数据流策略&#xf…...

【数据结构与算法】贪心算法及例题

目录 贪心算法例题一&#xff1a;找零问题例题二&#xff1a;走廊搬运物品最优方案问题输入样例例题三&#xff1a;贪心自助餐 贪心算法 贪心算法是一种在每一步选择中都采取当前状态下最优的选择&#xff0c;以期望最终达到全局最优解的算法。它的核心思想是每次都选择当前最…...

【Origin+Python】使用External Python批量出图代码参考

目录 基本介绍环境配置官方代码示例基础代码详解我的代码效果视频进阶代码及去水印 基本介绍 origin2021后可以使用python实现批量绘图&#xff0c;一共有两种方式&#xff1a;一种是嵌入式Python&#xff0c;一种是外部Python访问Origin。详细介绍可以自己去查看&#xff0c;打…...

YOLOv8最新改进系列:融合DySample超轻量动态上采样算子,低延迟、高性能,目前最新上采样方法!!!遥遥领先!

YOLOv8最新改进系列&#xff1a;融合DySample超轻量动态上采样算子&#xff0c;低延迟、高性能&#xff0c;目前最新上采样方法&#xff01;&#xff01;&#xff01;遥遥领先&#xff01; DySample超轻量动态上采样算子全文戳这&#xff01;here! 详细的改进教程以及源码&am…...

ChatGPT基础(二) ChatGPT的使用和调优

文章目录 ChatGPT的特性采用关键词进行提问给ChatGPT指定身份提升问答质量的策略1.表述方式上的优化2.用"继续"输出长内容3.营造场景4.由浅入深&#xff0c;提升问题质量5.预设回答框架和风格 ChatGPT的特性 1.能够联系上下文进行回答 ChatGPT回答问题是有上下文的&…...

麒麟 V10 离线 安装 k8s 和kuboard

目录 安装文件准备 主机准备 主机配置 修改主机名&#xff08;三个节点分别执行&#xff09; 配置hosts&#xff08;所有节点&#xff09; 关闭防火墙、selinux、swap、dnsmasq(所有节点) 安装依赖包&#xff08;所有节点&#xff09; 系统参数设置(所有节点) 时间同步…...

PlayerSettings.WebGL.emscriptenArgs设置无效的问题

1&#xff09;PlayerSettings.WebGL.emscriptenArgs设置无效的问题 2&#xff09;多个小资源包合并为大资源包的疑问 3&#xff09;AssetBundle在移动设备上丢失 4&#xff09;Unity云渲染插件RenderStreaming&#xff0c;如何实现多用户分别有独立的操作 这是第381篇UWA技术知…...

项目管理工具——使用甘特图制定项目计划的详细步骤

甘特图是一种直观的项目管理工具&#xff0c;它有助于我们清晰地展示任务安排、时间管理和项目的进度。以下是使用甘特图制定项目计划的详细步骤&#xff1a; 1、创建项目&#xff1a;首先&#xff0c;在进度猫中创建新的项目&#xff0c;并设置项目的时间、工作日等参数。根据…...

python读取文件数据写入到数据库中,并反向从数据库读取保存到本地

学python&#xff0c;操作数据库是必不可少的&#xff0c;不光要会写python代码&#xff0c;还要会写SQL语句&#xff0c;本篇文章主要讲如何把本地txt文件中的数据读取出来并写入到对应的数据库中&#xff0c;同时将数据库单个表中的数据读出来保存在本地txt文件中。 话不多说…...

社交媒体数据恢复:Viber

Viber是一款流行的即时通讯应用&#xff0c;用于发送消息、语音通话和视频通话。然而&#xff0c;有时候我们会不小心删除一些重要的Viber聊天记录&#xff0c;这时候就需要进行数据恢复。本文将介绍如何在安卓设备上进行Viber数据恢复。 一、使用安卓数据恢复软件 安卓数据恢…...

蓝桥杯赛事介绍

蓝桥杯是由工业和信息化部人才交流中心主办的全国性IT学科赛事&#xff0c;全称为“蓝桥杯全国软件和信息技术专业人才大赛”。该赛事旨在推动软件和信息领域专业技术人才培养&#xff0c;提升大学生的创新能力和就业竞争力&#xff0c;为行业输送具有创新能力和实践能力的高端…...

TypeScript系列之-深度理解基本类型画图讲解

JS的类型(8)&#xff1a; null undefined string number boolean bigint symbol object&#xff08;含 Array, Function,Date.....&#xff09; TS的类型(87): 以上所有&#xff0c;加上 void, never, enum, unknown, any 再加上自定义类型 type interface 上一节我们说…...

Debian

使用root用户操作 直接使用su命令进行切换。 配置用户使用sudo命令 在安装好系统之后&#xff0c;使用用户名登录之后。需要执行需要root权限的命令&#xff0c;会发现无法执行成功。原因是没有配置用户使用sudo的权限。 编辑bash /etc/sudoers文件 可以先切换root用户安装…...

怎么使用JMeter进行性能测试?

一、简介 JMeter是Apache软件基金会下的一款开源的性能测试工具&#xff0c;完全由Java开发。它专注于对我们应用程序进行负载测试和性能测量&#xff0c;最初设计用于web应用程序&#xff0c;现在已经扩展到其他测试功能&#xff0c;比如&#xff1a;FTP、Database和LDAP等。…...

MySQL:锁的分类

文章目录 行级锁Record LockGap LockNext-Key Lock插入意向锁 表级锁表锁元数据锁&#xff08;MDL&#xff09;意向锁AUTO-INC 锁 全局锁 行级锁 Record Lock 记录锁有S锁&#xff08;共享锁/读锁&#xff09;和X锁&#xff08;排他锁/写锁&#xff09;之分&#xff0c;加完S…...

基于springboot实现房屋租赁管理系统设计项目【项目源码+论文说明】

基于springboot实现房屋租赁管理系统设计演示 摘要 互联网发展至今&#xff0c;无论是其理论还是技术都已经成熟&#xff0c;而且它广泛参与在社会中的方方面面。它让信息都可以通过网络传播&#xff0c;搭配信息管理工具可以很好地为人们提供服务。针对房屋租赁信息管理混乱&…...

揭秘Redis底层:一窥数据结构的奥秘与魅力

一、引言 Redis&#xff0c;以其高性能、高可靠、丰富的数据结构等特点&#xff0c;成为现代应用程序中不可或缺的缓存与存储组件。然而&#xff0c;Redis之所以能够实现如此卓越的性能&#xff0c;离不开其底层精巧的数据结构设计。本文将深入浅出地解析Redis底层五大核心数据…...

【网站项目】智能停车场管理系统小程序

&#x1f64a;作者简介&#xff1a;拥有多年开发工作经验&#xff0c;分享技术代码帮助学生学习&#xff0c;独立完成自己的项目或者毕业设计。 代码可以私聊博主获取。&#x1f339;赠送计算机毕业设计600个选题excel文件&#xff0c;帮助大学选题。赠送开题报告模板&#xff…...

芒果YOLOv5改进94:检测头篇DynamicHead为目标检测统一检测头:即插即用|DynamicHead检测头,尺度感知、空间感知、任务感知

该专栏完整目录链接: 芒果YOLOv5深度改进教程 该创新点:在原始的Dynamic Head的基础上,对核心部位进行了二次的改进,在 原论文 《尺度感知、空间感知、任务感知》 的基础上,在 通道感知 的层级上进行了增强,关注每个像素点的比重。 在自己的数据集上改进,有效涨点就可以…...

获奖名单出炉,OurBMC开源大赛总决赛圆满落幕

4 月 12 日&#xff0c;由开放原子开源基金会牵头、OurBMC 社区及理事长单位飞腾信息技术有限公司联合承办的 OurBMC 开源大赛总决赛在江苏宿迁圆满落幕。共有 10 支参赛队伍凭着初赛的优异表现进入决赛&#xff0c;在路演现场上演了一场精彩绝伦的对决。 江苏省工信厅软件和信…...

Qt配置外部库(Windows平台)

这里以C的外部库nlopt为例子来示范&#xff0c;右键工程选择添加库&#xff0c;然后选择库文件的目录&#xff08;dll.a&#xff09;&#xff0c;会自动设置好包含路径&#xff08;一般是include的目录&#xff09;&#xff0c;添加库&#xff08;最下面一行&#xff09; &…...

(最新)华为 2024 届实习招聘-硬件通⽤/单板开发——第十一套和十二套

&#xff08;最新&#xff09;华为 2024 届实习招聘-硬件通⽤/单板开发——第十一套和十二套 部分题目分享&#xff0c;完整版带答案(有答案和解析&#xff0c;答案非官方&#xff0c;未仔细校正&#xff0c;仅供参考&#xff09;&#xff08;共十套&#xff09;获取&#xff…...

js纯前端实现语音播报,朗读功能(2024-04-15)

实现语音播报要有两个原生API 分别是【window.speechSynthesis】【SpeechSynthesisUtterance】 项目代码 // 执行函数 initVoice({text: 项目介绍,vol: 1,rate: 1 })// 函数 export function initVoice(config) {window.speechSynthesis.cancel();//播报前建议调用取消的函数…...

PostgreSQL数据库基础--简易版

数据库 其中runoobdb为数据库名 查看已经存在的数据库 \l进入数据库 \c runoobdb创建数据库 CREATE DATABASE runoobdb;删除数据库 DROP DATABASE runoobdb;表 其中COMPANY为表名 创建表格 CREATE TABLE COMPANY(ID INT PRIMARY KEY NOT NULL,NAME TEXT…...

前端解析URL的两种方式

方法一&#xff1a;利用 splice 分割 循环依次取出 方法一&#xff1a; function queryURLparams(url) {let obj {}if (url.indexOf(?) < 0) return objlet arr url.split(?)url arr[1]let array url.split(&)for (let i 0; i < array.length; i) {let arr2…...

Linux的学习之路:6、Linux编译器-gcc/g++使用

摘要 本文主要是说一些gcc的使用&#xff0c;g和gcc使用一样就没有特殊讲述。 目录 摘要 一、背景知识 二、gcc如何完成 1、预处理(进行宏替换) 2、编译&#xff08;生成汇编&#xff09; 3、汇编&#xff08;生成机器可识别代码 4、链接&#xff08;生成可执行文件或…...

分享2024 golang学习路线

写在前面 Go语言&#xff08;也称为Golang&#xff09;是Google开发的一种静态强类型、编译型语言&#xff0c;它具有简洁、快速、安全、并发等特点&#xff0c;尤其适合构建大型软件、微服务架构和云平台服务。Go的学习曲线相对平缓&#xff0c;社区活跃&#xff0c;是现代编…...

【Linux】进程间通信——system V版本 共享内存

目录 共享内存 原理 实践 shmget() 创建共享内存 shmctl() 删除共享内存 shmat() 挂接进程和共享内存 shmt() 进程和共享内存去关联 共享内存的特性 优势 劣势 用共享内存实现进程间通信 共享内存 原理 两个进程的PCB各自维护着一个进程地址空间。当两个进…...

【TEE论文】IceClave: A Trusted Execution Environment for In-Storage Computing

摘要 使用现代固态硬盘&#xff08;SSD&#xff09;的存储中计算使开发人员能够将程序从主机转移到SSD上。这被证明是缓解I/O瓶颈的有效方法。为了促进存储中计算&#xff0c;已经提出了许多框架。然而&#xff0c;其中很少有框架将存储中的安全性作为首要任务。具体而言&…...

昭通昭阳区城乡建设管理局网站/怎么做好seo内容优化

一、题目要求 随着论坛的发展&#xff0c;管理员发现水王没有了&#xff0c;但是统计结果表明&#xff0c;有三个发帖很多的ID。据统计他们的发帖数量超过了1/4&#xff0c;你能从发帖列表中快速找到他们吗&#xff1f;二、设计思想 通过数每次ID出现的次数来排除一部分&#x…...

如何把电脑改成服务器 做网站/百度网站关键词排名助手

背景 本人双非渣本 今年由于疫情&#xff0c;上半年一直在家里。2月份本来无忧无虑&#xff0c;呆在家里不给国家添乱的时候&#xff0c;发现身边的同学找到了大厂的offer。心里开始有点慌张。本来想在3月份如果能回到学校&#xff0c;就开始考研之路&#xff0c;但谁曾想这个…...

linux下载wordpress/保定网站seo

姓名年龄性别职位死亡时间所在行业死亡原因注信息来源王江民59岁男酷6网研发部 软件工程师2010.4.4IT心脏病死亡时仅 入职3个月百度百科罗耀明80后男江民创始人 兼总裁2009.11.0IT急性病毒 性心肌炎加班 彭小琦30岁左右男搜狐无线事业部 技术人员2010.4.0IT过度劳累 导致猝死工…...

网站建设流程 知乎/全国疫情的最新数据

解题思路和代码原型来源于牛课网&#xff0c; 我自己实现了一遍&#xff0c;添加了部分注释 1 package problems_2016_08_10;2 3 import java.util.LinkedList;4 /*5 总述&#xff1a;6 一共有五个函数分别是&#xff1a;7 8 getvalue…...

做网站编辑好吗/人力资源培训网

2019独角兽企业重金招聘Python工程师标准>>> 最近在坛子里看到有人用mysqlimport的问题很多&#xff0c;自己写了点&#xff0c;希望各位指正。 我的环境是&#xff1a;windowsXP sp2,奔D双核2.8G&#xff0c;1G DDR2 533MHZ内存&#xff0c;MYSQL5.1 mysqlimport位…...

如何网站点击率/产品品牌策划方案

实现一个栈&#xff0c;栈初始为空&#xff0c;支持四种操作&#xff1a; push x – 向栈顶插入一个数 x&#xff1b;pop – 从栈顶弹出一个数&#xff1b;empty – 判断栈是否为空&#xff1b;query – 查询栈顶元素。 现在要对栈进行 MM 个操作&#xff0c;其中的每个操作 3…...