Entries from 2022-01-01 to 1 year

『C++入門 AtCoder Programming Guide for beginners (APG4b)』を読みながら取ったメモ

atcoder.jp こちらの教材を読みながら問題も解いた.学びになった項目をメモした. T - 2.03.多次元配列 U - 2.04.参照 複数の返り値を得る 無駄なコピーを減らす 範囲 for 文 V - 2.05.再帰関数 Z - 3.02.pair/tupleとauto AA - 3.03.STLのコンテナ AC - 3…

『競プロのための標準 C++』を読みながら取ったメモ

zenn.dev こちらの書籍を読みながら知らなかった項目を実装しながらメモ. 01 string 02 vector 03 numeric 04 unordered_set 05 algorithm 06 tuple 07 ios, iomanip 01 string string型で宣言した変数は初期化しなければカラ.サイズは0. string 変数名(n…

数値誤差

atcoder.jp を解いていての学び. 参考 drken1215.hatenablog.com 数値誤差 #include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ios::sync_with_stdio(false); cin.tie(0); double a= 2.51; cout << (int) (a*100) << endl; return 0; } 250</bits/stdc++.h>…

範囲for文

C++

範囲for文というループの書き方を知らなかったのでメモ. 参考 atcoder.jp 上記サイトからの引用 #include <bits/stdc++.h> using namespace std; int main() { vector<int> a = {1, 3, 2, 5}; for (int x : a) { cout << x << endl; } } 1 3 2 5 範囲for文はコンテナと呼ばれる</int></bits/stdc++.h>…

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>…

std::set

atcoder.jp 簡単な問題だけど std::set を初めて使ったのでメモ. #include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); set<int> s; for (int i = 0; i < 3; i++) { int x; cin >> x; s.insert(x); } if(s.size() == 2) { cout </int></bits/stdc++.h>…

std::cout の小数点以下の表示桁数を変更

C++

cout << setprecision(12) << ans << endl; 以下のように書くと小数点が0でも指定した表示桁数で表示する cout << fixed << setprecision(12) << ans << endl;

1文字だけ大文字から小文字に変換する

atcoder.jp C++ の練習がてら上の問題を解いていて,ググって出てくるのが std::transform とかを使う方法がほとんどだったけど,アルファベットの文字コードが大文字と小文字で 32 異なるということを利用するのがシンプル(だしこの問題の模範解答)だった…