上に書く呪文

using namespace std;
#include<bits/stdc++.h>
void _main();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);_main();return 0;}
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;typedef long double ld;template<class ll> inline bool chmax(ll& a, ll b) { if (a < b) { a = b; return 1; } return 0; }template<class ll> inline bool chmin(ll& a, ll b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i, star,fini) for (ll i = star; i < fini; i++)
#define ALL(x) std::begin(x), std::end(x)
#define INF ((1LL<<62)-(1LL<<31))
#define bit(x,i)(((x)>>(i))&1)

//入力を受け取りつつ宣言する
inline void scan(){}
template<class Head,class... Tail>
inline void scan(Head&head,Tail&... tail){std::cin>>head;scan(tail...);}
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)

inline void print(){}
template<class Head,class... Tail>
inline void print(Head&head,Tail&... tail){std::cout<<head<<" ";print(tail...);cout<<endl;}

//vectorのcout,cin
template<typename T>
std::istream &operator>>(std::istream&is,std::vector<T>&v){for(T &in:v){is>>in;}return is;}
template<typename T>
std::ostream &operator<<(std::ostream&os,const std::vector<T>&v){for(auto it=std::begin(v);it!=std::end(v);){os<<*it<<((++it)!=std::end(v)?" ":"");}return os;}

long double my_distance(long double xi,long double yi,long double xj,long double yj){return sqrt(abs((xi-xj)*(xi-xj))+abs((yi-yj)*(yi-yj)));}
//Union-Find from <https://zenn.dev/reputeless/books/standard-cpp-for-competitive-programming/viewer/union-find>
class UnionFind{public:UnionFind() = default;//注:0-indexed
	explicit UnionFind(size_t n): m_parentsOrSize(n, -1) {}
	int find(int i){if (m_parentsOrSize[i] < 0){return i;}return (m_parentsOrSize[i] = find(m_parentsOrSize[i]));}
	void merge(int a, int b){a = find(a);b = find(b);if (a != b){if (-m_parentsOrSize[a] < -m_parentsOrSize[b]){std::swap(a, b);}m_parentsOrSize[a] += m_parentsOrSize[b];m_parentsOrSize[b] = a;}}
	bool connected(int a, int b){return (find(a) == find(b));}
	int size(int i){return -m_parentsOrSize[find(i)];}
    private:std::vector<int> m_parentsOrSize;
};
ll modpow(ll a,ll n,ll mod){ll res=1;while(n>0){if(n&1)res=res*a%mod;a=a*a%mod;n>>=1;}return res;}
ll modinv(ll a, ll mod){return modpow(a,mod-2,mod);}
bool iskaibun(string s){ll k = s.size();rep(i,0,k/2){if(s[i]!=s[k-1-i]){return false;}}return true;}
void _main(){
    print("Hello world");
}

入出力

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    cout << n << endl;
}

使える文

if-else if - else文、for文、switch文→C#と同じ。省略

min,max,abs

do-while→while文は処理を行う前に条件式を判定しているが、do-while文では、処理を行った後に条件式を判定している。

配列の宣言

vector<int> l(10);
//配列に入力を入れる
for(int i = 0;i<n;i++)
{
	cin >> l[i];
}

配列のrotate

int main()
{
    vector<int> vec = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    rotate(vec.begin(), vec.begin() + 3, vec.end());
		//[ 4, 5, 6, 7, 8, 9, 10, 1, 2, 3 ]
}

文字列の長さ

string s = "";
s.length();
s.size();

配列に要素を追加

vector.push_back(追加したい要素)

ランレングス圧縮

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string n;
    cin >> n;
    char a ;
    int ln = n.length();
    vector<int> lun(ln);
    vector<char> lc(ln);
    vector<char> l(0);
    int ka = 0;
    int b = 0;
    for(char i:n)
    {
        if(i==a)
        {
            lun[ka] += 1;
        }
        else
        {
            b += 1;
            a = i;
            ka += 1;
            lun[ka] = 1;
            lc[ka] = i;
        }

    }

    for(int j = 1;j<b;j++)
    {
        l.push_back(lc[j]);
        l.push_back(lun[j]);
        cout << (lc[j]) << (lun[j]);
    }
    cout << endl;
}

小さい方、大きい方へ変更

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
chmin(変更元,比べる先);
chmax(変更元,比べる先);