import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.LineNumberReader; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Random; import java.util.TreeMap;
public class CaiPiao { //1: 江苏网站提取 2:全国体彩分析 3:江苏体彩分析 4:生成七位数 5:江苏网站文本分析排序 //6:逆顺文件生成 7:3的分析与实际对比(江苏) static int type = 4; static String QuanGuo_ShuJu = "D:\\CaiPiao\\QuanGuo.txt"; static String JiangSu_ShuJu = "D:\\CaiPiao\\JiangSu.txt"; static String R_QuanGuo_ShuJu = "D:\\CaiPiao\\R_QuanGuo.txt"; static String R_JiangSu_ShuJu = "D:\\CaiPiao\\R_JiangSu.txt"; static String JiangSu_PHP_Folder = "F:\\ticai\\"; static String JiangSu_www_Copy = "d:\\CaiPiao\\tem.txt"; //type == 5时用 static boolean isWriteToFile = true; //type == 5时用 直接把数据写到文件里 static int groupCount = 10; //生成几组七位数 static int canShu1 = 1; static double MinGaiLu = 0.092; //第一次随机的数,以前的概率小于MinGaiLu,则再随机一次 static int lastCompareCount_ = 10; //type = 7时用来产生最近几期的对比 static int[][] bitNotActive_ = new int[][]{{-1}, {-1}, {-1}, {7, 6}, {8}, {-1}, {7}}; //{-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1} //最近好久没出现的号,-1代表无。全部为-1就是正常的按以前的概率选号 static double[][] GaiLu = new double[][] { {0.0935613682, 0.1116700201, 0.0935613682, 0.0995975855, 0.0885311871, 0.1006036217, 0.1056338028, 0.1156941650, 0.0935613682, 0.0975855131}, {0.1136820926, 0.0895372233, 0.1036217304, 0.1177062374, 0.1066398390, 0.0875251509, 0.1056338028, 0.0985915493, 0.0835010060, 0.0935613682}, {0.1026156942, 0.1056338028, 0.0995975855, 0.0985915493, 0.0935613682, 0.0855130785, 0.1066398390, 0.1076458753, 0.1016096579, 0.0985915493}, {0.0965794769, 0.0955734406, 0.0774647887, 0.1116700201, 0.1207243461, 0.1016096579, 0.0945674044, 0.1046277666, 0.0895372233, 0.1076458753}, {0.1036217304, 0.0915492958, 0.0975855131, 0.0975855131, 0.0885311871, 0.1086519115, 0.1056338028, 0.1006036217, 0.1046277666, 0.1016096579}, {0.1156941650, 0.0955734406, 0.0955734406, 0.0865191147, 0.1056338028, 0.0875251509, 0.0995975855, 0.1096579477, 0.0975855131, 0.1066398390}, {0.1056338028, 0.1016096579, 0.1096579477, 0.1056338028, 0.0875251509, 0.0855130785, 0.0985915493, 0.1066398390, 0.1016096579, 0.0975855131} }; public static void main(String[] args) throws Exception { if (type == 1) { Type1Function(); } else if (type == 2) { Type2Function(); } else if (type == 3) { Type3Function(); } else if (type == 4) { Type4Function(); } else if (type == 5) { Type5Function(); } else if (type == 6) { Type6Function(); } else if (type == 7) { Type7Function(lastCompareCount_); } System.out.println("Over!"); } static int getMaxQiOfJiangSu() { int MaxQi = 7000; try { BufferedReader reader = new BufferedReader(new FileReader(JiangSu_ShuJu)); while (reader.ready()) { String line = reader.readLine(); if (line == null || line.equals("") || line.length() < 12) { continue; } int qi = (new Integer(line.split("-")[0])).intValue(); MaxQi = MaxQi >= qi ? MaxQi : qi; } } catch (Exception e) { System.out.println(e); return -1; } return MaxQi; } static void addToMap(String line, TreeMap map) { String[] lineSplits = line.split(" "); if (lineSplits.length < 8) { return; } StringBuffer bf = new StringBuffer(); for (int i = 1; i <= 7; i++) { bf.append(lineSplits[i]); } map.put(new Integer(lineSplits[0]), bf.toString()); } static boolean isIssue(String s) throws Exception { return (s.indexOf("target=\"_blank\">0") != -1 && s.indexOf("</a> </td>") != -1); } static int getOneNumber(String s) throws Exception { return "0123456789".indexOf(s.split(">")[1].charAt(0)); // int num = -1; // return num; } static String getSevenNumber(LineNumberReader reader) throws Exception { String str = ""; for (int i = 0; i < 7; i++) { String s = reader.readLine(); str += getOneNumber(s); } return str; } static int getIssueNumber(String s) throws Exception { return Integer.parseInt(s.split("target=\"_blank\">")[1].split("<")[0]); // int num = -1; // return num; } static void printArray(int[][] nums, int count) { DecimalFormat df = new DecimalFormat("0.0000000000"); System.out.println("new double[][] {"); for (int i = 0; i < 7; i++) { System.out.print("{"); // df.format((((double)BitNumSum[i][k]) / list.size())) for (int k = 0; k < 10; k++) { System.out.print(df.format((((double)nums[i][k]) / count))); if (k != 9) System.out.print(", "); } if (i ==6) System.out.println("}"); else System.out.println("},"); } System.out.println("};"); } static int[] getNums(String s) throws Exception { int[] nums = new int[7]; for (int i = 0; i < 7; i++) { nums[i] = "0123456789".indexOf(s.charAt(i)); } return nums; } static void Type1Function() throws Exception { //江苏网站提取 TreeMap map = new TreeMap(); for (int i = 1; i <= 93; i++) { try { LineNumberReader reader = new LineNumberReader(new FileReader(JiangSu_PHP_Folder + "7_lssj(" + i + ").php")); String line; while(reader.ready()) { line = reader.readLine(); if (isIssue(line)) { map.put(new Integer(getIssueNumber(line)), getSevenNumber(reader)); } } // int count = 0; // reader.readLine(); // System.out.println(reader.getLineNumber() + reader.readLine()); } catch (Exception e) { System.out.println(e); continue; } } int size = map.size(); System.out.println(size); int count = 0; for (int i = 0; i < size; i++) { Integer issueNum = (Integer)map.firstKey(); String sevenNum = (String)map.get(issueNum); System.out.println(issueNum.toString() + "-" + sevenNum); count++; // if (count % 5 == 0) { // System.out.println(); // } else { // System.out.print(" "); // } map.remove(issueNum); } } static void Type2Function() throws Exception { //全国体彩 BufferedReader reader = new BufferedReader(new FileReader(QuanGuo_ShuJu)); reader.readLine(); ArrayList list = new ArrayList(); //new int[7] DecimalFormat df = new DecimalFormat("0.0000000000"); int[][] BitNumSum = new int[7][10]; int[] numbers; long[] sum = new long[]{0, 0, 0, 0, 0, 0, 0}; String[] strs; while(reader.ready()) { numbers = new int[7]; strs = reader.readLine().split(" "); for (int i = 0; i < 7; i++) { numbers[i] = Integer.parseInt(strs[i + 1]); } list.add(numbers); } for (int i = 0; i < list.size(); i++) { numbers = (int[])list.get(i); for (int k = 0; k < 7; k++) { BitNumSum[k][numbers[k]]++; sum[k] += numbers[k]; System.out.print(numbers[k] + " "); } System.out.println(); } // Random rm = new Random(System.currentTimeMillis()); System.out.println(list.size()); System.out.print("和数:"); for (int k = 0; k < 7; k++) { System.out.print(sum[k] + " "); } System.out.println(); System.out.print("平均数:"); for (int k = 0; k < 7; k++) { System.out.print((((double)sum[k]) / list.size()) + " "); } System.out.println(); System.out.println("0-10概率:"); for (int k = 0; k < 10; k++) { System.out.print(k + " "); for (int i = 0; i < 7; i++) { System.out.print(df.format((((double)BitNumSum[i][k]) / list.size())) + " "); } System.out.println(); } } static void Type3Function() throws Exception { //江苏体彩 BufferedReader reader = new BufferedReader(new FileReader(JiangSu_ShuJu)); ArrayList list = new ArrayList();//七位数集合 String str; int[] lineNum; //一个七位数 long[] sum = new long[]{0, 0, 0, 0, 0, 0, 0}; //七个位置中每一个位置,以前抽奖号码的和 DecimalFormat df = new DecimalFormat("0.0000000000"); int[][] BitNumSum = new int[7][10];//七个位置中每一个位置中0-9分别出现的次数 int[] numbers; while (reader.ready()) { str = reader.readLine().split("-")[1]; if (str.length() == 7) { lineNum = getNums(str); list.add(lineNum); } } for (int i = 0; i < list.size(); i++) { numbers = (int[])list.get(i); for (int k = 0; k < 7; k++) { BitNumSum[k][numbers[k]]++; sum[k] += numbers[k]; System.out.print(numbers[k] + " "); } System.out.println(); } // Random rm = new Random(System.currentTimeMillis()); System.out.println(list.size()); System.out.print("和数:"); for (int k = 0; k < 7; k++) { System.out.print(sum[k] + " "); } System.out.println(); System.out.print("平均数:"); for (int k = 0; k < 7; k++) { System.out.print((((double)sum[k]) / list.size()) + " "); } System.out.println(); System.out.println("0-10概率:"); for (int k = 0; k < 10; k++) { System.out.print(k + " "); for (int i = 0; i < 7; i++) { System.out.print(df.format((((double)BitNumSum[i][k]) / list.size())) + " "); } System.out.println(); } printArray(BitNumSum, list.size()); { int Pcount = 200; int Size = list.size(); int[][] bit = new int[7][10]; int[][][] bitBaiQi = new int[100][7][10]; for (int i = 0; i < Pcount; i++) {//打印Pcount期彩票每位数出现的次数 System.out.println("最近" + (i + 1) + "期"); bit = new int[7][10]; for (int k = Size; k >= Size - i; k--) { int[] aGroup = (int[])list.get(k - 1); if (aGroup.length == 7) { for (int m = 0; m < aGroup.length; m++) { bit[m][aGroup[m]]++; if (i < 100) bitBaiQi[i][m][aGroup[m]]++; } } } for (int n = 0; n < 10; n++) { System.out.print(n + " : \t"); for (int m = 0; m < 7; m++) { System.out.print(bit[m][n] + "\t"); } System.out.println(); } System.out.println(); } int maxZeroIndex = 7; for (int i = 7; i < bitBaiQi.length; i++) { if (maxZeroIndex >= i) { continue; } for (int m = 0; m < bitBaiQi[i].length; m++) { if (maxZeroIndex >= i) { break; } for (int n = 0; n < bitBaiQi[i][m].length; n++) { if (bitBaiQi[i][m][n] == 0) { maxZeroIndex = i; break; } } } } boolean[][] bFlag = new boolean[7][10]; System.out.println(); for (int i = 0; i < 7; i++) { System.out.print("\t" + (i + 1)); } System.out.println(); for (int qiShu = maxZeroIndex; qiShu >= 0; qiShu--) { System.out.print("\n"); System.out.print(qiShu + "\t"); for (int m = 0; m < bitBaiQi[qiShu].length; m++) { for (int n = 0; n < bitBaiQi[qiShu][m].length; n++) { if (!bFlag[m][n] && bitBaiQi[qiShu][m][n] == 0) { bFlag[m][n] = true; System.out.print(n); } } System.out.print("\t"); } } System.out.println(); } } static void Type4Function() throws Exception { boolean flagType4Function = false; for (int i = 0; i < bitNotActive_.length; i++) { if (flagType4Function) { break; } for (int k = 0; k < bitNotActive_[i].length; k++) { if (bitNotActive_[i][k] >= 0 && bitNotActive_[i][k] <= 9) { flagType4Function = true; break; } } } Random rm = new Random(System.currentTimeMillis()); int[][] nums = Type4FunctionIn(rm, groupCount); boolean[] flagOK = new boolean[groupCount]; while (flagType4Function) { int needGroupCount = 0; for (int i = 0; i < groupCount; i++) { if (!flagOK[i]) { if (Type4FunctionIsNotActive(nums[i])) { flagOK[i] = true; } else { needGroupCount++; } } } if (needGroupCount == 0) { break; } int[][] numsTemp = Type4FunctionIn(rm, needGroupCount); int numsTempIndex = 0; for (int i = 0; i < groupCount; i++) { if (!flagOK[i]) { System.arraycopy(numsTemp[numsTempIndex], 0, nums[i], 0, nums[i].length); numsTempIndex++; } } } for (int i = 0; i < groupCount; i++) { for (int k = 0; k < 7; k++) { System.out.print(nums[i][k] + " "); } System.out.println(); } } static boolean Type4FunctionIsNotActive(int[] nums) { for (int i = 0; i < bitNotActive_.length; i++) { for (int k = 0; k < bitNotActive_[i].length; k++) { if (nums[i] == bitNotActive_[i][k]) { return true; } } } return false; } static int[][] Type4FunctionIn(Random rm, int needGroupCount) throws Exception { //生成七位数 int[][] nums = new int[needGroupCount][7]; for (int i = 0; i < needGroupCount; i++) { for (int k = 0; k < 7; k++) { int num = (int) (Math.abs(rm.nextLong()) % 10); if (GaiLu[k][num] < MinGaiLu) { num = (int) (Math.abs(rm.nextLong()) % 10); } nums[i][k] = num; // System.out.print(num + " "); } // System.out.println(); } int flag = 0; while(flag < needGroupCount) { for (int i = flag; i < needGroupCount; i++) { int counttem = 0; for (int k = 0; k < 7; k++) { if (GaiLu[k][nums[i][k]] >= MinGaiLu) { counttem++; } } if (counttem <= canShu1) { flag = i; for (int m = 0; m < 7; m++) { nums[i][m] = (int) (Math.abs(rm.nextLong()) % 10); } break; } flag = i + 1; } } return nums; } static void Type5Function () throws Exception { BufferedReader reader = new BufferedReader(new FileReader(JiangSu_www_Copy)); BufferedWriter writer = new BufferedWriter(new FileWriter(JiangSu_ShuJu, true)); TreeMap map = new TreeMap(); String line; int MaxQi = getMaxQiOfJiangSu(); if (MaxQi == -1) { return; } while (reader.ready()) { line = reader.readLine(); if (line == null || line.equals("") || line.length() < 12) { continue; } addToMap(line, map); } int size = map.size(); int count = 0; for (int i = 0; i < size; i++) { Integer issueNum = (Integer)map.firstKey(); String sevenNum = (String)map.get(issueNum); String oneQi = issueNum.toString() + "-" + sevenNum; System.out.println(oneQi); count++; map.remove(issueNum); if (issueNum.intValue() > MaxQi && isWriteToFile) { writer.newLine(); writer.write(oneQi, 0, oneQi.length()); } } writer.flush(); } static void Type6Function() throws Exception { for (int i = 0; i <= 1; i++) { BufferedReader reader = new BufferedReader(new FileReader(i == 0 ? JiangSu_ShuJu : QuanGuo_ShuJu )); BufferedWriter writer = new BufferedWriter(new FileWriter(i == 0 ? R_JiangSu_ShuJu : R_QuanGuo_ShuJu )); ArrayList list = new ArrayList(); String line; while (reader.ready()) { line = reader.readLine(); if (line == null || line.equals("") || line.length() < 12) { continue; } list.add(line); } reader.close(); int count = list.size(); String lineseparator = System.getProperty("line.separator"); if (i == 0) { for (int index = count - 1; index >= 0; index--) { line = (String)list.get(index); writer.write(line + lineseparator); } } else { for (int index = count - 1; index >= 1; index--) { line = (String)list.get(index); writer.write(line.substring(0, 20) + lineseparator); } } writer.flush(); writer.close(); } } static void Type7Function(int num) throws Exception { //江苏体彩 BufferedReader reader = new BufferedReader(new FileReader(JiangSu_ShuJu)); ArrayList list = new ArrayList();//七位数集合 String str; int[] lineNum; //一个七位数 long[] sum = new long[]{0, 0, 0, 0, 0, 0, 0}; //七个位置中每一个位置,以前抽奖号码的和 int[][] BitNumSum = new int[7][10];//七个位置中每一个位置中0-9分别出现的次数 int[] numbers; while (reader.ready()) { str = reader.readLine().split("-")[1]; if (str.length() == 7) { lineNum = getNums(str); list.add(lineNum); } } for (int i = 0; i < list.size(); i++) { numbers = (int[])list.get(i); for (int k = 0; k < 7; k++) { BitNumSum[k][numbers[k]]++; sum[k] += numbers[k]; } } for (int index = 0; index < num; index++) { numbers = (int[])(list.get(list.size() - index - 1)); System.out.print("\n\n\n" + (char)('A' + index)); for (int i = 0; i < numbers.length; i++) { System.out.print("\t" + numbers[i]); } System.out.println(); int Pcount = 200; int Size = list.size() - index - 2; int[][][] bitBaiQi = new int[100][7][10]; for (int i = 0; i < Pcount; i++) {//打印Pcount期彩票每位数出现的次数 for (int k = Size; k >= Size - i; k--) { int[] aGroup = (int[])list.get(k - 1); if (aGroup.length == 7) { for (int m = 0; m < aGroup.length; m++) { if (i < 100) bitBaiQi[i][m][aGroup[m]]++; } } } } int maxZeroIndex = 7; for (int i = 7; i < bitBaiQi.length; i++) { if (maxZeroIndex >= i) { continue; } for (int m = 0; m < bitBaiQi[i].length; m++) { if (maxZeroIndex >= i) { break; } for (int n = 0; n < bitBaiQi[i][m].length; n++) { if (bitBaiQi[i][m][n] == 0) { maxZeroIndex = i; break; } } } } boolean[][] bFlag = new boolean[7][10]; System.out.println(); for (int i = 0; i < 7; i++) { System.out.print("\t" + (i + 1)); } System.out.println(); for (int qiShu = maxZeroIndex; qiShu >= 0; qiShu--) { System.out.print("\n"); System.out.print(qiShu + "\t"); for (int m = 0; m < bitBaiQi[qiShu].length; m++) { for (int n = 0; n < bitBaiQi[qiShu][m].length; n++) { if (!bFlag[m][n] && bitBaiQi[qiShu][m][n] == 0) { bFlag[m][n] = true; System.out.print(n); } } System.out.print("\t"); } } System.out.println(); } } }
|
|
|
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
---|
29 | 30 | 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 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|
导航
统计
- 随笔: 115
- 文章: 1
- 评论: 86
- 引用: 0
常用链接
留言簿(5)
随笔档案(115)
网址
搜索
积分与排名
最新评论
阅读排行榜
评论排行榜
|
|