在论文的实验中要实现在数据集中提取目标经纬度,通过识别指定标识符方法提取经纬度。本人水平有限,写的代码巨麻烦,时间复杂度为O(n3)。希望得到指点。
此为数据集内容:
0 2010-10-09T05:45:25Z 39.891077 -105.068532 6f3a2db56d4fa788f72def616f79b7a4 0 2010-10-08T03:33:37Z 39.758974 -105.010853 11da318f0ea3c4a8f447500c543cb694 0 2010-10-08T00:38:51Z 39.747228 -104.994783 ce162b33ed2c7b98e2aced2799aa5b20 0 2010-10-07T23:38:04Z 39.752508 -104.996637 424eb3dd143292f9e013efa00486c907 3 2010-07-04T21:53:19Z 37.761114 -122.434559 0bfba36f93e7d7b1af9a47be0462c1c1 3 2010-07-04T06:57:44Z 37.740104 -122.438231 e0d90ce08dd211dd9d9e003048c0801e 2016 2009-05-01T07:25:28Z 34.715235 136.970332 dcf9ca6c361811de9186003048c0801e 2016 2009-05-01T04:56:03Z 34.709595 136.968872 bc68a152360311de91e6003048c10834 2016 2009-05-01T03:33:55Z 35.041763 137.044357 6d30e2c635f811de8ba1003048c0801e 2016 2009-04-30T11:36:19Z 35.590454 139.596802 4740990e357011dea269003048c0801e
此为做完之后得到的内容:
39.891077 -105.068532 39.758974 -105.010853 39.747228 -104.994783 39.752508 -104.996637 37.761114 -122.434559 37.740104 -122.438231 34.715235 136.970332 34.709595 136.968872 35.041763 137.044357 35.590454 139.596802
代码如下:
import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class RWtxt { public static void main(String[] args) { try { int i = 0; int k = 1; FileReader fis = new FileReader("data.txt"); FileWriter fos = new FileWriter("data_2.txt"); char[] input = new char[1]; int hasRead = 0; f1:while((hasRead = fis.read(input)) > 0) { if(input[0] == 90) { f2:while((hasRead = fis.read(input)) > 0) { if(input[0] == 9) { i++; } if(input[0] != 9) { fos.write(input); System.out.print(new String(input , 0 , hasRead)); } if(i == 2) { if(k == 1) { fos.write(9); System.out.print("\t"); k--; } } if(i == 3) { fos.write("\r\n"); System.out.print("\n"); i = 0; k = 1; break f2; } } } } fis.close(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }