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

Posted at

ABC417-A

問題の内容

文字列の改変

言語

Rust

解法

文字列の操作で解く
.replace_range(範囲,"もじ");

課題

  • 特になし

学んだこと

  • 変更する変数は必ずmutを宣言時につける!
  • 破壊的だから文字列長も変化することを考えて。
  • スライスをすると元の文字列を破壊せずに取り出せる
    こっちの方が簡潔だし、sを変数宣言しなくていいから楽
let result = &s[a..n-b];

提出内容

use proconio::input;

fn main() {
  input! {
    n: usize,
    a: usize,//start
    b: usize,//end
    mut s: String,
  }
  s.replace_range(n-b..n, "");
  s.replace_range(0..a, "");//破壊的だから文字列長を変更しないため
  println!("{}", s);
}

成績

  • 272Byte
  • AC
  • 1ms
  • 2088KiB
0
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
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?