标签:c语言
#include < stdio.h >
  
 #define NUM_CHARS 256
  
 main ( void )
 {
    int c;
    int done = 0;
    int thisIdx = 0;
    long frequrr[NUM_CHARS + 1];
    long thisVal = 0;
    long maxVal = 0;
    //initialize
    for ( thisIdx = 0; thisIdx <= NUM_CHARS; thisIdx++ )
    {
        frequrr[thisIdx] = 0;
    }
     
    while ( done == 0 )
    {
        c = getchar();
         
        if ( c == EOF )
        {
            done = 1;
        }
         
        if ( c < NUM_CHARS )
        {
            thisVal = ++frequrr[c];
            if ( thisVal > maxVal )
            {
                maxVal = thisVal;
            }
        }
        else 
        {
            thisVal = ++frequrr[NUM_CHARS];
            if ( thisVal > maxVal )
            {
                maxVal = thisVal;
            }
        }
    }for ( thisVal = maxVal; thisVal >0; thisVal-- )
    {
        printf ( "%2d |", thisVal );
        for ( thisIdx = 0; thisIdx <= NUM_CHARS; thisIdx++ )
        {
            if ( frequrr[thisIdx] >= thisVal )
            {
                printf ( "*" );
            }
            else if ( frequrr[thisIdx] > 0 )
            {
                printf ( " " );
            }
        }
        printf ( "\n" );
    }
    printf ( "   |_" );
    for ( thisIdx = 0; thisIdx < NUM_CHARS + 1; thisIdx++ )
    {
        if ( frequrr[thisIdx] > 0 )
        printf ( "_");
    }
    printf ( "\n    " );
    for ( thisIdx = 0; thisIdx < NUM_CHARS + 1; thisIdx++ )
    {
        if ( frequrr[thisIdx] > 0 )
        printf ( "%d", ( thisIdx + 1 ) / 100 );
    }
    printf ( "\n    " );
    for ( thisIdx = 0; thisIdx < NUM_CHARS + 1; thisIdx++ )
    {
        if ( frequrr[thisIdx] > 0 )
        printf ( "%d", ( thisIdx + 1 ) / 10 % 10 );
    }
    printf ( "\n    " );
    for ( thisIdx = 0; thisIdx < NUM_CHARS + 1; thisIdx++ )
    {
        if ( frequrr[thisIdx] > 0 )
        printf ( "%d", ( thisIdx + 1 ) % 10 );
    }
    printf ( "\n" );
    return 0;
 }标签:c语言
原文地址:http://blog.csdn.net/u011694809/article/details/46120827