一個mfc簡單字符串壓縮程序;按以下情況進行壓縮;文章來源:http://www.zghlxwxcb.cn/news/detail-733169.html
1 僅壓縮連續(xù)重復出現(xiàn)的字符。比如”abcbc”無連續(xù)重復字符,壓縮后還是”abcbc”。
2 壓縮的格式為”字符重復的次數+字符”。例如,”xxxyyyyyyz”壓縮后就成為”3x6yz”。文章來源地址http://www.zghlxwxcb.cn/news/detail-733169.html
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 >
到了這里,關于MFC簡單字符串壓縮程序的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!