我目前使用的是这个
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 字符组成。
我遇到了这个代码
输入:
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)?