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
|
// cl /EHsc /Ox /std:c++17 /utf-8 a.cpp
// clang++ -O3 -std=c++17 a.cpp
// g++ -O3 -std=c++17 a.cpp
#include <cctype>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
std::vector <std::string> to_digits( const std::string& s )
{
static const char* glyphs[3][12] = {
{ "▄▀▀▄", "▄█ ", "▄▀▀▄", "▄▀▀▄", "▄ █ ", "█▀▀▀", "▄▀▀ ", "▀▀▀█", "▄▀▀▄", "▄▀▀▄", " ", " " },
{ "█ █", " █ ", " ▄▄▀", " ▀▄", "█▄▄█▄", "▀▀▀▄", "█▀▀▄", " ▄▀ ", "▄▀▀▄", "▀▄▄█", " ", " " },
{ "▀▄▄▀", "▄█▄", "█▄▄▄", "▀▄▄▀", " █ ", "▀▄▄▀", "▀▄▄▀", " █ ", "▀▄▄▀", " ▄▄▀", "▄", " " },
};
static const std::string indices{ "0123456789. " };
std::vector <std::string> rs( std::size( glyphs ) );
// Transform s to every indexable glyph
for (char c : s)
{
auto n = indices.find( c );
if (n != indices.npos)
for (int k = 0; k < std::size( glyphs ); k++)
rs[k].append( glyphs[k][n] ).append( " " );
}
// Trim trailing spaces
if (!rs[0].empty())
for (auto& r : rs)
r.resize( r.size() - 1 );
return rs;
}
int main()
{
for (auto s : to_digits( "3.141 592 653" ))
std::cout << s << "\n";
}
|