差分
このページの2つのバージョン間の差分を表示します。
— | 練習問題の解答例_4 [2019/07/15 02:46] (現在) – 作成 - 外部編集 127.0.0.1 | ||
---|---|---|---|
行 1: | 行 1: | ||
+ | # 5' | ||
+ | |||
+ | <code java> | ||
+ | package train; | ||
+ | |||
+ | import java.io.BufferedReader; | ||
+ | import java.io.File; | ||
+ | import java.io.FileReader; | ||
+ | import java.util.ArrayList; | ||
+ | import java.util.Collections; | ||
+ | import java.util.Comparator; | ||
+ | import java.util.HashMap; | ||
+ | import java.util.Map; | ||
+ | |||
+ | public class Day4 { | ||
+ | |||
+ | static int k=21; | ||
+ | |||
+ | public static ArrayList< | ||
+ | ArrayList< | ||
+ | |||
+ | Collections.sort(mapValuesList, | ||
+ | @Override | ||
+ | public int compare(Map.Entry< | ||
+ | return ((Integer) entry2.getValue()).compareTo((Integer) entry1.getValue()); | ||
+ | } | ||
+ | }); | ||
+ | return mapValuesList; | ||
+ | } | ||
+ | |||
+ | public static String searchfor(HashMap< | ||
+ | |||
+ | String tempk2=kstr.substring(1, | ||
+ | String[] acgt={" | ||
+ | int maxcov=0; | ||
+ | String maxbp=""; | ||
+ | for(String a : acgt){ | ||
+ | if(map.get(tempk2+a)!=null && map.get(tempk2+a)> | ||
+ | maxbp=a; | ||
+ | maxcov=map.get(tempk2+a); | ||
+ | } | ||
+ | } | ||
+ | if(maxcov> | ||
+ | fin.add(tempk2+maxbp); | ||
+ | return maxbp+searchfor(map, | ||
+ | } | ||
+ | return ""; | ||
+ | } | ||
+ | |||
+ | public static String searchback(HashMap< | ||
+ | |||
+ | String tempk2=kstr.substring(0, | ||
+ | String[] acgt={" | ||
+ | int maxcov=0; | ||
+ | String maxbp=""; | ||
+ | for(String a : acgt){ | ||
+ | if(map.get(a+tempk2)!=null && map.get(a+tempk2)> | ||
+ | maxbp=a; | ||
+ | maxcov=map.get(a+tempk2); | ||
+ | } | ||
+ | } | ||
+ | if(maxcov> | ||
+ | fin.add(maxbp+tempk2); | ||
+ | return searchback(map, | ||
+ | } | ||
+ | return ""; | ||
+ | } | ||
+ | |||
+ | public static void main(String[] args) { | ||
+ | // TODO 自動生成されたメソッド・スタブ | ||
+ | |||
+ | HashMap< | ||
+ | File file = new File(" | ||
+ | BufferedReader br; | ||
+ | int n=0; | ||
+ | try { | ||
+ | br = new BufferedReader(new FileReader(file)); | ||
+ | String str = br.readLine(); | ||
+ | while(str != null){ | ||
+ | n++; | ||
+ | if(n%4==2){ | ||
+ | for(int i=0; | ||
+ | String tempk=str.substring(i, | ||
+ | if(map.get(tempk)==null){ | ||
+ | map.put(tempk, | ||
+ | }else{ | ||
+ | map.put(tempk, | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | if(n%400000==0){ | ||
+ | System.out.println(n/ | ||
+ | } | ||
+ | str = br.readLine(); | ||
+ | } | ||
+ | br.close(); | ||
+ | System.out.println(n/ | ||
+ | |||
+ | ArrayList< | ||
+ | ArrayList< | ||
+ | |||
+ | for(int i=0; | ||
+ | String tempk=sortedlist.get(i).getKey(); | ||
+ | if(!fin.contains(tempk)){ | ||
+ | fin.add(tempk); | ||
+ | String tempstr = searchback(map, | ||
+ | if(tempstr.length()> | ||
+ | System.out.println(">" | ||
+ | System.out.println(tempstr); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | } catch (Exception e) { | ||
+ | // TODO 自動生成された catch ブロック | ||
+ | e.printStackTrace(); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | さらに工夫すべき点としては、伸長するときに相補鎖を調べるとか、分岐しているような箇所は伸長せずに止めるとか、一定の出現頻度以下のk-merは無視するとか、色々と必要。 | ||
+ | |||