本文介绍了我为霍夫曼写这个程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include "StdAfx.h"
#include<string>
#include<iostream>
using namespace std ;
#define ARRAY_SIZE 20


int main()
{
	float hh [100] ;
	int i = 0 ;
	int n = 0 ;
	string sentence = " " ;
	float count[256] = { 0 } ;

	 cout << "Enter your sentences ( End the sentence with . ): " << endl ;
	 getline(cin,sentence);

  for( int n = 0 ; n < sentence.length() ; n++ )
  {
    count[sentence[n]]++ ;
  }

  float mm = sentence.length() - 1 ;

  for ( n = 0 ; n < 256 ; n++ )
  {
    if ( isalpha ( ( char ) n ) )
    {
      cout << ( char ) n << " has " <<  count[n] << " occurrences " << " and has   " << count[n] / mm << endl ;
	
		hh[ n ] = ( count[ n ] / mm ) ;
		i++ ;
			 cout << "yay" << hh[n] << endl ;
	}
	int counter = 0 ;
	if( hh[n] != 0 )
	{
		counter++ ;
	}

  //int iarray[ARRAY_SIZE];
  int x, y, holder;

  // Bubble sort method.
  for(x = 0; x < counter ; x++)
    for(y = 0; y < x-1 ; y++)
      if(hh[n] > hh[n+1])
	  {
        holder = hh[n+1];
        hh[n+1] = hh[n];
        hh[n] = holder;
		cout << hh[n] << "yay" ;
      } 
  }
  
   return 0;
}

推荐答案



int x, y, holder;

更改为

int x, y;
float holder;


这篇关于我为霍夫曼写这个程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 07:50