MFC简单字符串压缩程序-CSDN博客
阿里云国际版折扣https://www.yundadi.com |
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6 |
一个mfc简单字符串压缩程序;按以下情况进行压缩;
1 仅压缩连续重复出现的字符。比如”abcbc”无连续重复字符,压缩后还是”abcbc”。
2 压缩的格式为”字符重复的次数+字符”。例如,”xxxyyyyyyz”压缩后就成为”3x6yz”。
void CYssDlg::OnButton1()
{
// TODO: Add your control notification handler code here
char str[100] = {'\0'};
char res[100] = {'\0'};
CString strText;
GetDlgItemText(IDC_EDIT1, strText);
//str=strText.GetBuffer(strText.GetLength());
//WideCharToMultiByte(CP_ACP,0,str,strText.GetLength(),strText,strText.GetLength());
sprintf(str, "%s", strText);
int length = strlen(str);
int i=0, j=0, k=0;
int count = 0;
do
{
if(i < length && str[i++] == str[j])
count++;
if(str[i] != str[j])
{
if(count <= 1)
res[k++] = str[j];
else
{
if(count >