c语言函数字符串压缩 c语言压缩文件

下面的c语言字符串压缩程序怎么写呀? 输入样例 a5b3aba13b4 输出: aaaaabbbabaaaaaaaaaaaaabbbb#include stdio.h
#include stdlib.h//为了使用atoi函数
#include string.h//为了使用strlen函数
int main(void)
{
char input[100], temp;
char *p = input;
int i, j, len, tempint;
printf("请输入:");
scanf("%s", input);
len = strlen(input);
for (i=0; ilen; i)
{
if (*p='a'*p='z')
{
printf("%c", *p);
temp = *p;
p;
}
else if (*p='0'*p='9')
{
tempint = atoi(p);
for (j=1; jtempint; j)
printf("%c", temp);
while (*p='0'*p='9')
p;
}
}
return 0;
}
用C语言指针实现字符串压缩#includestdio.h
#define MAX_NUM 32int main()
{ char *p,str[60];
int i,j=0;
static int num[26];
p=(char*)malloc(MAX_NUM*sizeof(char));
gets(str);
for(i=0;str[i];i)
{if(str[i]==' ') p[j]=str[i];
else{
if(num[str[i]-97]==0||num[str[i]-97]==2||num[str[i]-97]==5)
{ p[j]=str[i];num[str[i]-97];}
elsenum[str[i]-97];
}}
for(i=0;ij;i)
putchar(p[i]);
getch();
return 0;
}注:输入的为小写字母,而且句子长度不超过60个字符,保存字数不超过32个 。。。。。在win_tc中通过……
C语言求助:请编写一个字符串压缩程序 , 将字符串中连续出席的重复字母进行压缩,并输出压缩后的字符串 。#include stdio.h
void stringZip(const char
*pInputStr, long lInputLen, char *pOutputStr)
{ int n=1;
char c,*p1=pInputStr,*p2=pOutputStr;
while(*p1)
{
c=*(p1);
while(*p1==c){n;p1;}
if(n1)
{
if(n999){*(p2)=48 n/1000; n/=10;}
if(n99){*(p2)=48 n/100; n/=10;}
if(n9){*(p2)=48 n/10; n/=10;}
*(p2)=48 n;
}
*(p2)=c;
n=1;
}
*p2='\0';
}
void main()
{ char s1[200],s2[200];
gets(s1);
【c语言函数字符串压缩 c语言压缩文件】 stringZip(s1,strlen(s1),s2);
puts(s2);
}
c语言 压缩字符串:如AABBCCDDDD,输出2A2B2C4D,用C语言,求问#includestdio.h
#includestring.h
void
main()
{
char
s[51];
int
i=0,j=1;
printf("请输入一个长度不超过五十的字符串(否则会越界出错):\n");
scanf("%s",s);
if(strlen(s)50){
printf("输入不合要求!");
return;
}
while(istrlen(s))
{
//j用于统计重复的字母个数
if(s[i]==s[i 1])
j;
else{
printf("%d%c",j,s[i]);
j=1;//j重新计数
}
i;
}
printf("\n");
}
不好意思昨晚写的,没仔细看,有错误 。
用C语言编程 字符串原地压缩 。题目:“eeeeeaaaff" 压缩为 "e5a3f2"把s字符串压缩处理后结果保存在res中#include stdio.h
#include stdbool.h
#include stdlib.h
#define MAX 50
typedef struct str
{
char ch;
int ccount;
struct str *next;
}node;
node *func(char a[],int n);
int main()
{
int index=0;
node *head,*head2,*temp;
char s[MAX],res[MAX];//最大输入字符可以自己设置
scanf("%s",s);
head2=head=func(s,sizeof(s));
while(head)
{
res[index]=head-ch;
res[index]=head-ccount 48;
head=head-next;
}
res[index]='\0';
printf("\nres=%s",res);
while(head2)
{
temp=head2-next;
free(head2);
head2=temp;
}
return 0;
}
node *func(char a[],int n)//把结果放在链表中 , 返回链表头
{
int i;
node *temp,*head,*head2,*head3;
bool new;
for(i=0;in;i)
{
if(i==0)
{
temp=(node *)malloc(sizeof(node));
temp-ch=a[i];
temp-ccount=0;
temp-next=NULL;
head=temp;
head3=head2=temp;
}
while(head3)//head3为了方便重置投指针
{
if(a[i]==head3-ch)
{
head3-ccount;
new=false;
break;
}
head3=head3-next;
new=true;
}
head3=head;
if(new)//head2指向最后一个链表
{
temp=(node *)malloc(sizeof(node));
temp-ch=a[i];
temp-ccount=1;
temp-next=NULL;
if((head2-next)!=NULL)
head2=head2-next;
head2-next=temp;
}
}
return head;
}
使用C语言实现字符串的压缩 。/*
原串: 111225555
压缩后: 312245
原串: 333AAAbbbb
压缩后: 333A4b
原串: ASXDCdddddd
压缩后: 1A1S1X1D1C6d
Press any key to continue
*/
#include stdio.h
#include string.h
char *CompressStr(char s[]) {
char t[255];
int i = 0,j,k = 0;
while(s[i]) {
j = i1;
while(s[i] == s[j])j;
t[k] = j - i'0';
t[k] = s[i];
i = j;
}
t[k] = '\0';
strcpy(s,t);
return s;
}
int main(void) {
char i,s[][20] = {"111225555","333AAAbbbb","ASXDCdddddd"};
for(i = 0; i3;i) {
printf("原串: %s\n",s[i]);
printf("压缩后: %s\n",CompressStr(s[i]));
}
return 0;
}
c语言函数字符串压缩的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于c语言压缩文件、c语言函数字符串压缩的信息别忘了在本站进行查找喔 。

    推荐阅读