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?

C++基本文法 チートシート

0
Last updated at Posted at 2026-10-11
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)
#define rez(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
using namespace std;

int main(){
    //ここにコード書く
}

入出力

    //入力
    cin >> N;

    //出力
    cout << S << endl;
    
    //大量出力
    cout << S << ":" << 1 << endl;

制御文

//for文
for(int i = 1; i <= N; i++) {
    cin >> A[i];
}


//repマクロ(最初に書いてたコピペテンプレを使った場合、上の処理と同じ意味)
rep(i, N){
    cin >> A[i];
}


//rez(rep zero)マクロ(使ってるの私だけ説)
string S = "Admin"
rez(i, size(S)){
    cout << S[i];
}
cout << endl;


//while文
int I = 1;
while(true){
    //この条件で処理を切る
    if(I > 100) break;
    
    cout << "I love you" << endl;

    //忘れず足そう
    I++;
}

vector

//大きさありとなし
vector<int> V;
vector<int> V(N + 9);

//末尾挿入
V.push_back(X);

//末尾削除
V.pop_back();

//二次元配列
vector<vector<int>> HW(H + 9, vector<int>(W + 9));

//参照
cout << HW[H][W] << endl;

STL関数

//小さいほうから並べる
sort(V.begin(), V.end());
sort(A + 1, A + N + 1); //NはAの範囲(1からNまでソートする場合はこう)

//逆向きにする
reverse(V.begin(), V.end());
reverse(A + 1, A + N + 1);

//絶対値
abs(a - b);

//max(同じ型じゃないとエラー)
max(a, b);
min(a, b);
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?