Skip to content

Instantly share code, notes, and snippets.

@qassa
Last active December 27, 2015 19:28
Show Gist options
  • Save qassa/7376752 to your computer and use it in GitHub Desktop.
Save qassa/7376752 to your computer and use it in GitHub Desktop.
пример простой архивации строки
#include<conio.h>
#include<stdio.h>
#include <string.h>
int main(){
char str[100], repeat;
gets(str);
int i=0, count = 1, k=0, tempCount =0, length=strlen(str);
repeat = str[0];
for (i=1;str[i]!='\0';i++)
{
if((str[i]!=repeat)&&(count>3))
{
tempCount = 0;
k=i-count;
str[k]='@';
str[k+1]=count+48;
str[k+2]=repeat;
for(k+=3;tempCount<length-count+1;k++,tempCount++)
{
str[k]=str[k+count-3];
}
i=i-count+3;
count=1; repeat=str[i];
}
else
if (str[i]!=repeat)
{
repeat=str[i];
count=1;
}
else
{
count++;
}
}
printf("\n%s",str);
for (i=1;str[i]!='\0';i++)
{
length=strlen(str);
if((str[i]>=48)&&(str[i]<=57))
{
tempCount=0;
count = (int)str[i]-48;
repeat = str[i+1];
for(k=length;tempCount<length-2;k--,tempCount++)
{
str[k+count-3]=str[k];
}
for(k=0,tempCount=i-1;k<count;tempCount++,k++)
{
str[tempCount]=repeat;
}
i=i+count-2;
}
}
printf("\n%s",str);
getch();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment