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?

C++キョウプロ用メモ

Posted at

C++キョウプロ用メモ

あくまでも趣味

書き方

AtCoderのいろんな人のコードを参考に
bits/stdc++.hはつかわない、なんとなく

呪文

入出力の同期を削除することで速くなるyo

#include<iostream>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

入力、出力

基本的にはendlでいいが、出力が多い場合\nを使う

#include<iostream>
using namespace std;
int main()
{
    int s;
    cin >> s;
    cout << s << endl;
}

vector

vectorのリファレンス

#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int N = 5;
    // 定義
    vector<int> V(N);
    // 入力
    for(int i=0; i<N; i++)
    {
        cin >> V[i];
    }
    // 確認
    for(int i=0; i<V.size(); i++)
    {
        cout << V[i] << endl;
    }
}

たまに見るやつ

#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int N = 5;
    vector<int> V(N);
    for(auto& v : V)
    {
        cin >> v;
    }
    
    for(const auto& v : V)
    {
        cout << v << endl;
    }
}

sort

sortのリファレンス

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    vector<int> V = {4, 3, 2, 1, 0};
    for(int v:V)cout << v << endl;
    
    sort(V.begin(), V.end());
    
    cout << "sort" << endl;
    for(int v:V)cout << v << endl;
}
4
3
2
1
0
sort
0
1
2
3
4

逆順はrbeginにする

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    vector<int> V = {0, 1, 2, 3, 4};
    for(int v:V)cout << v << endl;
    
    sort(V.rbegin(), V.rend());
    
    cout << "sort" << endl;
    for(int v:V)cout << v << endl;
}
0
1
2
3
4
sort
4
3
2
1
0
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?