字串的解壓縮

2021-06-18 07:50:46 字數 1057 閱讀 7341

問題描述:對字串進行解壓縮

例如:5w1g2b ---> wwwwwgbb

解決方案:

1.將輸入字串分別為集合5w、1g、2b,每個集合由乙個數字和乙個字元構成

2.從尾到頭讀取字串,當遇到乙個字元的時候,儲存下來;當遇到乙個數字的時候,我們開始建立乙個數,直到遇到下乙個字元

3.當遇到下乙個字元之前,我們應當擴充套件這個集合,例如(5w ---> wwwww),並儲存下來

4.因為遍歷是從尾到頭開始的,因此我們需要逆轉這個輸出結果。

#include #include #include #include #include /* reversal of a string */

void strreverse(char* str)

cpstr[strlen(str)] = '\0';

strcpy(str, cpstr);

}/* expand a set (5w ---> wwwww). here num = 5; byte = w; str is where the expansion is stored */

void putstringrep(int num,char byte,char* str)

byte = input[i]; //now proceed to capture the currently marked byte

//nullify these values in order to grab the next set's number

number = 0;

place = 0;

} else if(isdigit(input[i])) //當前字元是數字

}strreverse(output); //逆轉輸出

字串壓縮 解壓縮(時間優先)

字串壓縮 解壓縮 時間優先 壓縮 1 得到字串長度 利用長度申請一片新的記憶體newstr來儲存 2 遍歷源字串,如果不是 0 進入迴圈 宣告 pindex 來記錄當前 字元 repetitionlength 記錄重複的字元次數 3 pindex 與 pindex 1 進行比較 如果相等 repet...

學 Lazarus 字串壓縮 解壓縮

背景 1 原有c 開發的wince系統 webservice 2 客戶說wince上的終端程式執行速度慢,我也說慢 3 希望改造乙個wince上的終端程式,因為熟悉delphi所以lazarus 4 lazarus匯入的webservice 我看不明白,還涉及到資料型別轉換神馬的,決定放棄webse...

字串編碼解壓縮演算法

前幾天,有乙個學c的小夥伴和我交流乙個問題,問題他是這麼說的 傳入乙個字串,格式要求如下 ep a2d3b4c1d2 那麼將這個字串解壓的結果應為 aadddbbbbcdd 規則就是,必須滿足,字串的第乙個是字母,可以大寫也可以小寫,第二個為數字,範圍為1 9,解壓的長度不得超過1000個字元。按照...