問題: 運行長度編碼(RLE)是一種簡單的「壓縮算法」(一種算法,它採用一個數據塊並減小其大小,產生一個包含相同信息的塊更小的空間)。它通過用代表整個序列的短「代幣」來代替相同數據項的重複序列。將RLE應用於字符串涉及在相同字符重複的字符串中查找序列。每個這樣的序列應該由「令牌」替換爲:編寫程序壓縮字符串
the number of characters in the sequence
the repeating character
如果一個字符不重複,它應該被單獨留下。
例如,請考慮以下字符串:
qwwwwwwwwweeeeerrtyyyyyqqqqwEErTTT
應用RLE算法後,這個字符串轉換成:
q9w5e2rt5y4qw2Er3T
這是我到目前爲止,我不知道知道如何計算角色的重複次數。有人可以幫助!!!!
public class Compress1 {
public static void main(String[] args){
System.out.println("Enter a string");
String input = IO.readString();
char[] inputChar = input.toCharArray();
for (int index = 0; index < inputChar.length; index++){
char current = inputChar[index];
if (current == (current + 1)){
int count =
}
}
}
}