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

AOJ 0039 - Roman figure

aoj

書くだけでした. #include <iostream> int rfiguretonum(char r){ if(r == 'I')return 1; if(r == 'V')return 5; if(r == 'X')return 10; if(r == 'L')return 50; if(r == 'C')return 100; if(r == 'D')return 500; if(r == 'M')return 1000; return 0; } int main(){</iostream>…

AOJ 0035 - Is it convex?

aoj

汚いコードができあがりました. 無駄に外積を使い,三角形内に点があれば凸四角形であると判定します. #include <iostream> #include <cstdio> class Point{ public: Point(); Point(double _x, double _y); double x, y; }; Point::Point() : x(0), y(0){} Point::Point(dou</cstdio></iostream>…

AOJ 0080 - Third root

aoj

小数第10位までだと落ちてしまったので,サンプル出力のように6位までにしました. #include <iostream> #include <cmath> #include <cstdio> int main(){ double q, x; while(std::cin >> q, q != -1){ x = q/2; while(fabs(x*x*x-q) >= 0.00001*q){ x = x - (x*x*x-q) / (3*x*x); } </cstdio></cmath></iostream>…

AOJ 0078 - Magic Square

aoj

適切な位置を考えてから入れました. #include <iostream> #include <cstdio> #include <cstring> int main(){ int n, square[15][15], count = 0; while(std::cin >> n, n){ count = 0; memset(square, 0, sizeof(square)); int x = n/2, y = n/2+1; square[y][x] = ++count; while(cou</cstring></cstdio></iostream>…

AOJ 0228 - Seven Segments

ビット演算をつかいました. XORをつかいます. #include <cstdio> void binarywrite(int n){ for(int i=6;i>=0;i--){ printf("%d", (n >> i & 1)); } puts(""); } int main(){ int lights[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x27, 0x7f, 0x6f}; int n</cstdio>…

AOJ 0174 - Badminton

連想配列, readlnを使ってみた. 連想配列は使っていないキーで取得しようとするとエラーが出るんですね. そのため,最初にキー'A', 'B'に対して0を代入しています. readlnは改行文字も含まれているのですね. import std.stdio; void main(){ string s; w…