📄 1.cpp
字号:
#include "stdio.h"
#include "string.h"
#include "iostream.h"
#define maxvalue 1000
#define maxleaf 30
#define maxnode maxleaf*2-1
#define maxbit 30
typedef struct
{
int weight;
int parent;
int lchild;
int rchild;
}hnodetype;
typedef struct
{
int bit[maxbit];
int start;
}hcodetype;
char * getcode(char *s1,char *s2,char *s3);
char * getcode1(char *s1);
void huffmantree(char *s2,char s3[]);
void main()
{
char s1[maxleaf],s2[maxleaf];
gets(s1);
strcpy(s2,getcode(s1," ",""));
//puts(s2);
huffmantree(s1,getcode1(s2));
//puts(s1);
}
char * getcode(char *s1,char *s2,char *s3)
{
char * p,*q,temp[128]="";
p=s1;
while((q=strstr(p,s2))!=NULL)
{
*q='\0';
strcat(temp,p);
strcat(temp,s3);
p=q+strlen(s2);
}
strcat(temp,p);
strcpy(s1,temp);
return s1;
}
char * getcode1(char *s1)
{
int m,i,j,temp1,k,t;
t=0;
i=0;
m=strlen(s1);
while(*(s1+i)!='\0')
{
temp1=s1[i];
j=i+1;
while(*(s1+j)!='\0')
{
if(temp1==*(s1+j))
{
k=j;
while(*(s1+k)!='\0')
{
*(s1+k)=*(s1+k+1);
k++;
}
j--;
}
j++;
}
i++;
}
puts(s1);
return s1;
}
/*
char * getcode1(char *s1)
{
char s2[26],s5[26];
char temp[200]="",*p,*q,*r,*s3="";
int m,e,n=0;
m=strlen(s1);
while(m>0)
{
p=s1;
s2[0]=s1[0];
s2[1]='\0';
r=s2;
e=0;
while((q=strstr(p,s2))!=NULL)
{
*q='\0';
e++;
strcat(temp,p);
strcat(temp,s3);
p=q+strlen(s2);
}
m-=e;
strcat(s1,temp);
strcpy(p,temp);
s5[n]=s2[0];
n++;
strcpy(temp,"");
}
// puts(s5);
s5[n]='\0';
strcpy(s1,s5);
// puts(s1);
return s1;
}*/
void huffmantree(char *s2,char s3[])
{
hnodetype huffnode[maxnode];
hcodetype huffcode[maxleaf],cd;
int sum,i,j,n1,n2,x1,x2,p,k,c;
char s5[maxleaf];
char s1[26];
int ww[26]={0},n=0;
for(i=0;i<26;i++)
s1[i]='a'+i;
//puts(s2);
//puts(s3);
strcpy(s5,s2);
sum=strlen(s2);
printf("%d\n",sum);
for(i=0;i<26;i++)
{
for(j=0;j<sum;j++)
if(s2[j]==s1[i])
ww[i]++;
// printf("%d",ww[i]);
} //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -