2009-07-01から1ヶ月間の記事一覧

bitshift : decimal -> binary / 10進2進変換

C

ビットを扱うのって、苦手な人が多い気がする.自分ふくめ。 目に見えないからわかりにくいんだよね、たぶん。しかし、ビット演算は、つかえると非常に便利だとおもう。まだ便利に使えるほどつかえないけど。 #include <stdio.h> void dec2bin(const int decimal_orig</stdio.h>…

二分木

BTreeを書いた.集合型ということで. setと最小値を取り出すminpopのみサポート.木のバランスが崩れたときの再構築とかは考えていない. num === null) { $this->num = $x; } else { if ($this->num > $x) { $call = "left"; } else…

string -> int キャスト

C++

ようするに、1文字ずつ cast したらいいのかもしれないんだけど。 で、あれですね、static_cast(char) の場合、1文字が、asciiコードになるので、「 - '0'」とかしてやると数値になるわけですね。で、文字列をintにしてやろう、とか考えると、 #include <iostream> #in</iostream>…

string

C++

#include <iostream> #include <sstream> #include <string> using namespace std; int main() { string hoge = "hoge", fuga = "fuga"; // some method of std::string cout << hoge << endl; cout << hoge.length() << endl; cout << hoge.at(1) << endl; cout << hoge.substr(1,2) <<</string></sstream></iostream>…

SRM 146 DIV 1 300

はつとっぷこーだ。まあpracticeだけど。

vector::iterator

C++

久々にC++さわったらだいぶわすれてたからリハビリからはじめる。 #include <iostream> #include <vector> #include <string> using namespace std; void print_vector (string name, vector<int> &v) { cout << "vector:\t" << name << endl; int i = 0; for (vector<int>::iterator it = v.begi</int></int></string></vector></iostream>…

Git で不要になったローカルブランチ・リモートブランチの削除

Git

% git branch -a * master hoge origin/hoge % git branch -d hoge % git push origin :hoge:hoge でリモートブランチの削除になるの。 わかりづらい気がするよ!

Git で svn export 的なやつ

Git

忘れがちなので.. % git checkout-index -a -f --prefix=../hoge/ prefix は末尾に / をちゃんと入れないと悲惨なことになる.

Linux コマンド再入門 (cut, sort, uniq)

で。Linux (Unix) には、コマンドラインで色々できるものが揃っているので、これ使えるか使えないかで、大きな差がでてしまうな、と最近つくづく思う。いわゆる、GNU Coreutilsというやつだ。*1 実は知らなくても生きていけるし、Ruby や Python 書けば適当…