Skip to content

Commit

Permalink
sorts: Replace flatten()
Browse files Browse the repository at this point in the history
  • Loading branch information
XuShaohua committed Feb 25, 2024
1 parent e12e830 commit 7a4eba5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions math/src/num_of_digits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub const fn num_digits(num: i64) -> usize {

/// Find the number of digits in a number.
///
/// abs() is used as logarithm for negative numbers is not defined.
/// `abs()` is used as logarithm for negative numbers is not defined.
#[must_use]
pub fn num_digits_fast(num: i64) -> usize {
if num == 0 {
Expand All @@ -38,7 +38,7 @@ pub fn num_digits_fast(num: i64) -> usize {

/// Find the number of digits in a number.
///
/// abs() is used for negative numbers
/// `abs()` is used for negative numbers
#[must_use]
pub fn num_digits_faster(num: i64) -> usize {
num.abs().to_string().len()
Expand Down
10 changes: 5 additions & 5 deletions sorts/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ where
pub fn read_ints() -> Vec<i32> {
let mut v = vec![];
let buffer = BufReader::new(io::stdin());
let input_iter = buffer.lines();
for line in input_iter.flatten() {
let mut input_iter = buffer.lines();
while let Some(Ok(line)) = input_iter.next() {
for word in line.split_whitespace() {
let value = word.parse::<i32>().expect("Invalid integer");
v.push(value);
Expand All @@ -65,11 +65,11 @@ pub fn read_ints() -> Vec<i32> {
#[must_use]
pub fn read_strings() -> Vec<String> {
let buffer = BufReader::new(io::stdin());
let input_iter = buffer.lines();
let mut input_iter = buffer.lines();
let mut v = vec![];
for line in input_iter.flatten() {
while let Some(Ok(line)) = input_iter.next() {
for word in line.split_whitespace() {
v.push(word.to_string());
v.push(word.to_owned());
}
}
v
Expand Down

0 comments on commit 7a4eba5

Please sign in to comment.