バイナリクロック
Posted feedbacks - C++
本体より文字列変換のほうが長くなってしまいました。
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 | #include <iostream>
#include <string>
#include <limits>
#include <cassert>
#include <ctime>
template<typename T>
std::string tobits(T n, int d)
{
assert(n > 0);
assert((0 < d) && (d <= std::numeric_limits<T>::digits));
std::string result;
for(T i = static_cast<T>(1) << (d - 1); i > 0; i >>= 1)
{
result += ((n & i) != 0) ? "■" : "□";
}
return result;
}
int main(int, char* [])
{
std::time_t raw;
std::time(&raw);
std::tm* t = std::localtime(&raw);
std::cout << tobits(t->tm_hour, 6) << "\n"
<< tobits(t->tm_min, 6) << "\n"
<< tobits(t->tm_sec, 6) << "\n";
return 0;
}
|



lunlumo #9282() [ Ruby ] Rating6/8=0.75
20:18の場合,例えば以下の様な出力をするイメージです。
出力例:
■□■□□
□■□□■□
see: Binary Clock Widget
Rating6/8=0.75-0+
[ reply ]