java實現字元壓縮演算法
public class CompressionAlgorithm1 {
/**
* @param args
* 實現簡易字串壓縮演算法:一個長度最大為128的字串,
* 由字母a-z或者A-Z組成,將其中連續出現2次以上(含2次)的字母轉換為字母和出現次數,
* 以達到壓縮目的。
* 輸入:AAAABBBB
* 輸出:A4B4
*/
public static String outPutStr(String InputStr){
//首先先獲取字串的第一個字元
int i=0;
StringBuffer outputStr=new StringBuffer();;
int length=InputStr.length();
while(i<length){
//依次獲取字元
char a=InputStr.charAt(i);
int number=1;
//然後判斷這個字元之後是否還有相同的字元
for(int j=i+1;j<length;j++){
char b=InputStr.charAt(j);
//判斷 a和b是否相等
if(a==b){
number++;
}else{
//跳出本次迴圈,進入下一個迴圈
break;
}
}
//將字元進行壓縮
if(number>1){
//如果number大於1那就表明可以壓縮
outputStr.append(a+new Integer(number).toString());
}else{
outputStr.append(a);
}
//將獲取number新增進i
i=i+number;
}
return outputStr.toString();
}
public static void main(String[] args) {
String inputStr=“ABccTTThhKKKL”;
System.out.println(outPutStr(inputStr));
}
}
U2FsdGVkX1+wpPCHgX6LBjU3CRl+ieR1/M/BwSoDyz1VowGhY2ecjd3cpxUtrZoS
EOaCJPUmBidHgi5F0H2hasYe3VzN8YRvXHEMl18Ym/A6w+aY4Cov58aKc6lhsvYZ
UG43cNFym3v2Wtnnhqh3Kr8+HXBR1OHMAMgOlmCgwm+4mCq3OPnVWKShC6mcWDMl
Icm+r4FKD1FjIbI6IvhvilFGRma+gWgm/Sitka+efCbWo5dy+G4yZm3zYZi+PFJP
GpQgXBy27+M1HxUh16q/cgydACA4GC+f15pWb7CZRSyRWvHYYhkoFMqKSN6ywyPU
/jDWeSvbmyefJF3Q+kNeXo9dgoRSahni73zpAsJdHF38qxy+O40jQb99JH1v0ZcX
7CM/wZiyU6S+UpG9CNSWZIzI8I3rmLksNxJ4XxTxP6Lg0cX5Quu2l8HzKEI9a+JA
c4wBVeUfK5qwFWbcPJMhuACUPxCAqUyFCY+ULjm1HMTpZwxfvUJfKf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yPVkhAt4wWTI
r3bn9DWCU6oXWZCQ2HzGXNRqH5948qIw13Nl19+iJqpofKfS/42N6Rkt2DWVyBIq
ZF1V5qbI7BNF7JbZMMCyVw==
相關文章
- 利用Java實現zip壓縮/解壓縮 (轉)Java
- JAVA基礎:利用Java實現zip壓縮解壓縮(轉)Java
- Java實現壓縮資料夾Java
- Python實現壓縮和解壓縮Python
- JAVA壓縮和解壓縮Java
- java字串初步壓縮演算法Java字串演算法
- 20.1 OpenSSL 字元BASE64壓縮演算法字元演算法
- 壓縮Word,一鍵實現Word文件壓縮
- Flutter實現Luban圖片壓縮庫演算法Flutter演算法
- PAT1078字串壓縮與解壓(java實現)字串Java
- Java實現檔案壓縮與解壓[zip格式,gzip格式]Java
- java實現zip壓縮檔案/資料夾Java
- Java 實現壓縮圖片,影片,音訊案例Java音訊
- 貪心演算法——Huffman 壓縮編碼的實現演算法
- Java實現解壓縮檔案和資料夾Java
- Java實現多檔案邊壓縮邊下載Java
- java使用google開源工具實現圖片壓縮JavaGo開源工具
- JNI實現圖片壓縮
- 用ASP實現線上壓縮與解壓縮功能程式碼
- Java壓縮htmlJavaHTML
- Java不同壓縮演算法的效能比較Java演算法
- 哈夫曼實現檔案壓縮解壓縮(c語言)C語言
- Asp.net實現線上壓縮與解壓ASP.NET
- 利用 canvas 實現圖片壓縮Canvas
- 利用 canvas 實現資料壓縮Canvas
- 資料壓縮演算法:LZ77 演算法的分析與實現演算法
- 用 Huffman 樹實現檔案壓縮並解壓
- Java檔案壓縮Java
- Java使用Zip壓縮Java
- java 檔案壓縮Java
- canvas實現的前端壓縮裁剪工具Canvas前端
- 有人成功使用FILTER實現壓縮嗎 ??????Filter
- 【shell】用shell實現自動壓縮日誌並且清理壓縮包
- 壓縮演算法一覽演算法
- 壓縮字串《演算法很美》字串演算法
- C++ MiniZip實現目錄壓縮與解壓C++
- 使用org.apache.tools.zip實現zip壓縮和解壓Apache
- LZ77壓縮演算法編碼Python實現原理圖解演算法Python圖解