1
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に挑んだ軌跡-ABC415-A-

Posted at

ABC415-A

問題の内容

配列の検索

言語

Rust

解法

配列の先頭から順に検索して一致したYesを返す
全探索するのでflagを立てる。

課題

  • flagの立て方(ギャルゲーかな?)

学んだこと

  • break処理を入れる
    普通に
if flag == 1 {
    break;
}

でいいらしい。
ちなみに

flag = true;
flag = false;

の方がわかりやすくていい。

提出内容

use proconio::input;

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

なんか若干深くなってますけど見逃してください。

成績

  • 297Byte
  • AC
  • 1ms
  • 2096KiB
1
0
0

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
1
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?