0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

初心者プログラマーAtCoderに挑んだ軌跡-ABC413-A-

Posted at

ABC413-A

問題の内容

与えられた配列の合計+数の大小

言語

Rust

解法

配列の中身を合計してif文で比較

課題

  • input書く際の配列の中身でコンパイルエラー
    a: [usize;n],
    []の中身は","じゃなくて";"

学んだこと

  • 配列の合計は専用のものがある
let sum: usize = a.iter().sum();

iterは配列やベクタの要素を"借用"して順番に渡す
→順番に渡して合計する

提出内容

use proconio::input;

fn main() {
  input! {
    n: usize,
    m: usize,
    a: [usize;n],
  }
  let mut sum = 0;
  for i in 0..n {
    sum += a[i];
  }
  if sum <= m {
    println!("Yes");
  } else {
    println!("No");
  }
}

成績

  • 243Byte
  • AC
  • 1ms
  • 2064KiB
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?