小编Era*_*lon的帖子

在 Rust 中检查字符串是否以数字开头的更简单方法?

我目前使用的是这个

fn main() {
    let a = "abc123";
    let b = "1a2b3c";

    println!("{}", a[0..1].chars().all(char::is_numeric));
    println!("{}", b[0..1].chars().all(char::is_numeric));
}
Run Code Online (Sandbox Code Playgroud)

有没有更惯用和/或更简单的方法来做到这一点?

注意:该字符串保证非空且由 ASCII 字符组成。

string rust

4
推荐指数
1
解决办法
4672
查看次数

什么不是我们使用双数组?

我遇到了这个代码

输入:

3
0.1227...
0.517611738...
0.7341231223444344389923899277... 
Run Code Online (Sandbox Code Playgroud)
int N; 
char x[110]; 
int main() {
scanf("%d\n", &N);
while (N--) { 
scanf("0.%[0-9]...\n", &x); 
printf("the digits are 0.%s\n", x);
Run Code Online (Sandbox Code Playgroud)

我无法理解几件事:

1.为什么不使用double数组(因为输入值是double)?

2.scanf中[0-9]后的那三个点...有什么作用?和

3.为什么我们不在 scanf 中的 [0-9] 之后使用任何格式说明符(在这种情况下为 d)?

c c++ printf scanf

3
推荐指数
1
解决办法
123
查看次数

标签 统计

c ×1

c++ ×1

printf ×1

rust ×1

scanf ×1

string ×1