Entries from 2022-07-26 to 1 day

std::map で要素のカウント

atcoder.jp を解いてて他の方のコードを見ていて知ったのでメモ. この問題は最初に各文字で始まる文字列を数えておくと良いが,自分の実装では #include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int</bits/stdc++.h>…

std::set の要素参照

C++

std::set は二分探索木での実装なので operator[] でアクセスできない.イテレータを使う. #include <bits/stdc++.h> using namespace std; int main(){ set<int> st{3, 1, 4}; for (auto itr = st.begin(); itr != st.end(); ++itr) { cout << *itr << endl; } return 0; } 1 3</int></bits/stdc++.h>…