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

switch文のcaseでのブロック

C C++

switch文のcaseの中で変数宣言する場合は注意が必要です。 #include <iostream> using std::cout; using std::endl; int main () { switch(1) { case 1: int i = 0; break; case 2: int i = 0; break; } return 0; } $ cl /W4 /EHsc main.cpp Microsoft(R) 32-bit C/C+</iostream>…

A-starアルゴリズム

人材獲得作戦・4 試験問題ほか: 人生を書き換える者すらいた。この問題をC言語の勉強がてらやってみました。幅優先探索とか色々方法はあるみたいですが、A-starなんてアルゴリズムがあるらしく、折角なので調べながらやってみました。A* - Wikipedia #inclu…

上下左右をループで得るコード

C++

今日見たコードで凄いのがあった。 #include <iostream> using std::cout; using std::endl; int main () { for (int x = -1, y = 0, i = 0; i < 4; x += y, y = x - y, x = y - x, ++i) { cout << "x " << x << " y " << y << endl; } return 0; } $ main x -1 y 0 x </iostream>…