1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

C++ 競プロのためのTipsまとめ

1
Posted at

想定読者

  • AtCoderで 茶〜水 程度
  • C++使い

目的

  • 知らなくても支障はないものたちだけど、使えると便利だから貯めていく!(随時更新)

参照渡しで、入力値を配列に楽に入れる

  • 参照渡しをすると、配列に簡単に値を取り込める
  • 特に、複数の配列があり、それぞれ長さが異なるときに便利!
  • ref: 物理好きさんのABC246の解説
// 一度適当な変数を経由して入れる例
for (int i = 0; i < n; i++) {
    int tmp; cin >> tmp;
    a[i] = tmp;
}
// おすすめのやり方
for (auto &x : a) cin >> x;

配列の初期化方法

int a[n] = {}; // 0で埋められる
bool b[n] = {}; // falseで埋められる

行受け取り

string s;
getline(cin, s);
1
3
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
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?