2017-02-25から1日間の記事一覧

便利ワザ2

定数 const int N = 1000; const int inf = (int)1e9 + 1; const ll big = (ll)1e18 + 1; const int P = 31; const int MOD = (int)1e9 + 7; const int MOD1 = (int)1e9 + 9; const int MAX_INT = (1 << 31) - 1; const double eps = 1e-6; const double pi …

ABC053_B

文字列反転の問題 文字列反転は次のようにする. string str = "abcde"; reverse(str.begin(),str.end());//"edcba" #include <bits/stdc++.h> using namespace std; int main() { string str; cin>>str; int start=0,end=0; for(int i=0;i</bits/stdc++.h>

ABC055_B

factorialを求める問題 大きい数値はll型を使う. int型(4byte)の範囲は20億くらいを目安にする. #include <bits/stdc++.h> using namespace std; #define ll long long int #define MOD (ll)1e9+7 #define MAX(X,Y) ((X)>(Y)?(X):(Y)) #define MIN(X,Y) ((X)<(Y)?(X):(Y)) i</bits/stdc++.h>…

ABC025_A

文字列についての問題 文字列の要素1つはchar型だと知った. ex) string str = "abcde"; cout<<typeid(str[1]).name()<<endl; //c よってsubstr(ポインタの位置,そこから何文字分?)を使って部分文字列を使った. #include <bits/stdc++.h> using namespace std; int main() { string s; int n; vector<string> ss; cin>>s>>n; sort(s.begin(),s.end()); for(int i=0;i<5;i++){ for(int…</string></typeid(str[1]).name()<<endl;>

便利ワザ

入力に対して出力を行うのをプログラムがやってくれる. mainの後ろに置く. // ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); #endif

ABC046_A

種類を数える問題 集合(set)を用いる #include <bits/stdc++.h> using namespace std; int main() { int a,b,c; set<int> s; cin>>a>>b>>c; s.insert(a);//集合sにaを挿入 s.insert(b); s.insert(c); cout<</int></bits/stdc++.h>

標準ライブラリ一括インクルード

#include <bits/stdc++.h></bits/stdc++.h>

ABC050_A

文字列を分割して数値にする問題C++におけるsplit関数の実装 qiita.com #include <iostream> #include <cstdio> #include <string> #include <sstream> #include <vector> using namespace std; int stoi(std::string str){ int ret; std::stringstream ss; ss<<str; ss>>ret; return ret; } vector<string> split(const s</string></str;></vector></sstream></string></cstdio></iostream>…