當前位置:編程學習大全網 - 網站源碼 - C語言求助:請編寫壹個字符串壓縮程序,將字符串中連續出席的重復字母進行壓縮,並輸出壓縮後的字符串。

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(n>1)

{

if(n>999){*(p2++)=48+n/1000; n/=10;}

if(n>99){*(p2++)=48+n/100; n/=10;}

if(n>9){*(p2++)=48+n/10; n/=10;}

*(p2++)=48+n;

}

*(p2++)=c;

n=1;

}

*p2='\0';

}

void main()

{ char s1[200],s2[200];

gets(s1);

stringZip(s1,strlen(s1),s2);

puts(s2);

}

  • 上一篇:請問c++builder怎麽安裝opencv
  • 下一篇:給據郵政跟蹤查詢系統幫我查下sa02268799732到哪了
  • copyright 2024編程學習大全網