Submission #00088
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #include <bits/stdc++.h> using namespace std; void calc( int X, double Y) { if (X >= 256) { puts ( "NA" ); return ; } string P; for ( int i = 7; i >= 0; i--) { if ((X >> i) & 1) P += "1" ; else P += "0" ; } string Q; double base = 1.0; for ( int i = 0; i < 4; i++) { base /= 2; if (Y >= base) { Y -= base; Q += "1" ; } else { Q += "0" ; } } if ( fabs (Y) < 1e-8) { cout << P << "." << Q << endl; } else { puts ( "NA" ); } } int main() { for (;;) { string V; cin >> V; if (V[0] == '-' ) break ; int X = 0; double Y = 0.0; int ptr = 0; if (V.find( '.' ) == string::npos) V += "." ; while (V[ptr] != '.' ) { X = X * 10 + V[ptr] - '0' ; ++ptr; } ptr++; double base = 0.1; while (ptr < V.size()) { Y += base * (V[ptr] - '0' ); base /= 10; ++ptr; } calc(X, Y); } } |
ステータス
項目 | データ |
---|---|
問題 | 0005 - 博士の愛した2 進数 |
ユーザー名 | ei1333 |
投稿日時 | 2016-08-29 09:32:51 |
言語 | C++11 |
状態 | Accepted |
得点 | 9 |
ソースコード長 | 964 Byte |
最大実行時間 | 34 ms |
最大メモリ使用量 | 564 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 9 / 9 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
00.in | AC | 18 ms | 476 KB |
1
|
01.in | AC | 23 ms | 452 KB |
1
|
02.in | AC | 33 ms | 564 KB |
1
|
03.in | AC | 34 ms | 540 KB |
1
|