반응형
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | package imperfect; import java.net.HttpURLConnection; import java.net.URL; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.io.BufferedReader; import java.io.InputStreamReader; public class alpha { private static String Address; private static URL url; private static BufferedReader br; private static HttpURLConnection conn; private static String protocol = "GET"; private static int drwNo_; public static void main(String[] args) throws Exception { drwNo_ = 783; int drwNo = drwNo_; int[][] frequency = new int[2][drwNo_ * 6]; int i = 1; for (; drwNo >= 1; drwNo--) { System.out.println("-------" + drwNo + "-------"); String pattern1 = "alt=\""; String pattern2 = "\"/>"; Pattern p = Pattern.compile(pattern1 + "(.*?)" + pattern2); Address = "http://www.nlotto.co.kr/gameResult.do?method=byWin&drwNo=" + drwNo; url = new URL(Address); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod(protocol); br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "MS949")); Matcher m; String line; while ((line = br.readLine()) != null) { if (line.startsWith(" <img src=")) { m = p.matcher(line); while (m.find()) { System.out.println(m.group(1)); frequency[0][drwNo_ * 6 - i] = Integer.parseInt(m.group(1)); i++; } } if (line.startsWith(" <span class=\"number")) { System.out.println("Bonus"); m = p.matcher(line); while (m.find()) { System.out.println(m.group(1)); frequency[1][drwNo * 3 - 1] = Integer.parseInt(m.group(1)); } } } } String[][] chart = new String[2][45]; int[][] chart_num = new int[2][45]; int count = 0; // chart initialize for (int j = 0; j <= 1; j++) { for (String str : chart[j]) { chart[j][count] = ""; chart_num[j][count] = 0; count++; } count = 0; } count = 1; int main_total = 0, bonus_total = 0, out_total = 0; for (int type = 0; type <= 1; type++) { for (int num : frequency[type]) { if (num != 0) { chart[type][num - 1] += "■"; chart_num[type][num - 1]++; } } for (int j = 0; j < 45; j++) { if (type == 0) { main_total += chart_num[type][j]; } else { bonus_total += chart_num[type][j]; } } if (type == 0) { System.out.println("Main Number Frequency"); out_total = main_total; } else { System.out.println("Bonus Number Frequency"); out_total = bonus_total; } for (String str : chart[type]) { if (count < 10) { System.out.print("0"); } String percent = String.format("%.2f", ((double) chart_num[type][count - 1] / out_total) * 100.0); System.out.println(count + ":" + str + chart_num[type][count - 1] + "(" + percent + "%)"); count++; } count = 1; } System.out.println("Total Number Graph"); for (int j = 0; j < 45; j++) { if (count < 10) { System.out.print("0"); } String percent = String.format("%.2f", (((double) chart_num[0][j] + chart_num[1][j]) / (main_total + bonus_total)) * 100.0); System.out.println( count + ":" + chart[0][j] + chart[1][j] + (chart_num[0][j] + chart_num[1][j]) + "(" + percent + "%)"); count++; } } } | cs |
1회부터 drwNo회까지의 로또 추첨 번호를 파싱하여 가져옴.
매 회차 당첨번호를 출력하며, 메인번호(6자리), 보너스번호, 전체(7자리) 통계를 수치,비율과 함께 막대 그래프로 보여줌.
아래는 1회~783회까지의 통계 결과
참고링크.
http://jwchoi85.tistory.com/42
http://egloos.zum.com/penta82/v/4099027
https://stackoverflow.com/questions/11255353/java-best-way-to-grab-all-strings-between-two-strings-regex
https://jhkim2017.wordpress.com/2017/04/24/java-throws%EC%99%80-throw%EC%9D%98-%EC%B0%A8%EC%9D%B4/
https://blog.naver.com/occidere/220796488866
반응형