Números ASCII_ART

Publicado por Fernando (última atualização em 23/09/2017)

[ Hits: 2.014 ]

Homepage: https://github.com/phoemur/

Download numbers_asciiart.cpp




Este pequeno programa gera números grandes em stdout, a partir da linha de comando.

Compilando:

$ g++ numbers_asciiart.cpp -o numbers_asciiart

Executando:

$ ./numbers_asciiart 1234567890

  



Esconder código-fonte

#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

const char BIGDIGITS[10][7][6] =
            {{"  0  ",
              " 0 0 ", 
              "0   0", 
              "0   0", 
              "0   0", 
              " 0 0 ", 
              "  0  "},
             {"  1  ", 
              " 11  ", 
              "  1  ", 
              "  1  ", 
              "  1  ", 
              "  1  ", 
              " 111 "},
             {" 222 ", 
              "2   2", 
              "2  2 ", 
              "  2  ", 
              " 2   ", 
              "2    ", 
              "22222"},
             {" 333 ", 
              "3   3", 
              "    3", 
              "  33 ", 
              "    3", 
              "3   3", 
              " 333 "},
             {"   4 ", 
              "  44 ", 
              " 4 4 ", 
              "4  4 ", 
              "44444", 
              "   4 ", 
              "   4 "},
             {"55555", 
              "5    ", 
              "5    ", 
              " 555 ", 
              "    5", 
              "5   5", 
              " 555 "},
             {" 666 ", 
              "6    ", 
              "6    ", 
              "6666 ", 
              "6   6", 
              "6   6", 
              " 666 "},
             {"77777",
              "    7", 
              "   7 ", 
              "  7  ", 
              " 7   ", 
              "7    ", 
              "7    "},
             {" 888 ",
              "8   8", 
              "8   8", 
              " 888 ", 
              "8   8", 
              "8   8", 
              " 888 "},
             {" 9999", 
              "9   9", 
              "9   9", 
              " 9999", 
              "    9", 
              "    9", 
              "    9"}};

void printdigits(vector<int> * array) {
    for (int linha=0; linha<7;++linha) {
        for (vector<int>::size_type i = 0;i < array->size();++i) {
            cout << BIGDIGITS[array->at(i)][linha] << "  ";
        }
        cout << endl;
        cout.flush();
    }
    return;
}

int main(int argc, char* argv[]) {
    vector<int> * numeros;
    numeros = new (nothrow) vector<int>;
    for (int c=1; c<argc; ++c) {
        for (int i=0; i < strlen(argv[c]); ++i) {
            numeros->push_back(argv[c][i] - 48);
        }
        printdigits(numeros);
        numeros->clear();
    }
    delete numeros;
    return 0;
}

Scripts recomendados

indice.c - Indice em strings

Calcula diferença entre o maior e menos número digitado

Ler string invertida

Média de alturas

DATA POR EXTENSO


  

Comentários

Nenhum comentário foi encontrado.


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts