欢迎来到天天文库
浏览记录
ID:37845290
大小:27.50 KB
页数:3页
时间:2019-06-01
《java实现行程编码压缩》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、importjava.io.*;importjava.util.HashSet;importjava.util.Iterator;importjava.util.Scanner;publicclassbianma1{publicstaticvoidmain(String[]args){FileReaderreader=null;FileWriterwriter=null;BufferedReaderbin=null;BufferedWriterbout=null;Scannerscanner=null;HashSet2、er>set=newHashSet();Filefile=null;try{intcount[]=newint[300];reader=newFileReader("c:\原始数据.txt");writer=newFileWriter("c:\压缩文件.txt");bin=newBufferedReader(reader);bout=newBufferedWriter(writer);Strings=null;file=newFile("c:\原始数据.txt");scanner=newScanner(f3、ile);while(scanner.hasNext()){set.add(Integer.parseInt(scanner.next()));}Iteratoriterator=set.iterator();while(iterator.hasNext()){intp=iterator.next();count[p]=1;}System.out.println("压缩前的矩阵:");intd=1;while((s=bin.readLine())!=null){String[]a=s.split("\D+")4、;for(inti=0;iiterator1=set.iterator();if(a[i].equals(a[i+1])){while(iterator1.hasNext()){5、w=iterator1.next();if(q==w){t=w;count[t]++;}}if(i==a.length-2){bout.write(d+"t"+a[i]+"t"+(count[t])+"t"+"r");count[t]=1;}}if(!a[i].equals(a[i+1])&&i!=a.length-2){while(iterator1.hasNext()){w=iterator1.next();if(q==w){t=w;count[t]++;}}bout.write(d+"t"+a[i]+"t"6、+(count[t]-1)+"t"+"r");count[t]=1;}if(!a[i].equals(a[i+1])&&i==a.length-2){while(iterator1.hasNext()){w=iterator1.next();if(q==w){t=w;count[t]++;}}bout.write(d+"t"+a[i]+"t"+(count[t]-1)+"t"+"r"+d+"t"+a[i+1]+"t"+"1"+"t"+"r");count[t]=1;}}else;}d++;}}ca7、tch(IOExceptione){e.printStackTrace();}finally{try{bout.close();bin.close();reader.close();writer.close();}catch(Exceptione2){e2.printStackTrace();}}try{System.out.println("压缩后文件:");reader=newFileReader("c:\压缩文件.txt");bin=newBufferedReader(reader);Strings=null;while8、((s=bin.readLine())!=null){System.out.println(s);}}catch(Exceptione){e.printStackTrace();}finally{try{bin.close();reader.close();}c
2、er>set=newHashSet();Filefile=null;try{intcount[]=newint[300];reader=newFileReader("c:\原始数据.txt");writer=newFileWriter("c:\压缩文件.txt");bin=newBufferedReader(reader);bout=newBufferedWriter(writer);Strings=null;file=newFile("c:\原始数据.txt");scanner=newScanner(f
3、ile);while(scanner.hasNext()){set.add(Integer.parseInt(scanner.next()));}Iteratoriterator=set.iterator();while(iterator.hasNext()){intp=iterator.next();count[p]=1;}System.out.println("压缩前的矩阵:");intd=1;while((s=bin.readLine())!=null){String[]a=s.split("\D+")
4、;for(inti=0;iiterator1=set.iterator();if(a[i].equals(a[i+1])){while(iterator1.hasNext()){
5、w=iterator1.next();if(q==w){t=w;count[t]++;}}if(i==a.length-2){bout.write(d+"t"+a[i]+"t"+(count[t])+"t"+"r");count[t]=1;}}if(!a[i].equals(a[i+1])&&i!=a.length-2){while(iterator1.hasNext()){w=iterator1.next();if(q==w){t=w;count[t]++;}}bout.write(d+"t"+a[i]+"t"
6、+(count[t]-1)+"t"+"r");count[t]=1;}if(!a[i].equals(a[i+1])&&i==a.length-2){while(iterator1.hasNext()){w=iterator1.next();if(q==w){t=w;count[t]++;}}bout.write(d+"t"+a[i]+"t"+(count[t]-1)+"t"+"r"+d+"t"+a[i+1]+"t"+"1"+"t"+"r");count[t]=1;}}else;}d++;}}ca
7、tch(IOExceptione){e.printStackTrace();}finally{try{bout.close();bin.close();reader.close();writer.close();}catch(Exceptione2){e2.printStackTrace();}}try{System.out.println("压缩后文件:");reader=newFileReader("c:\压缩文件.txt");bin=newBufferedReader(reader);Strings=null;while
8、((s=bin.readLine())!=null){System.out.println(s);}}catch(Exceptione){e.printStackTrace();}finally{try{bin.close();reader.close();}c
此文档下载收益归作者所有