文件out.txt中,有如下内容:1237/0468/1237..0143*685
78569 十769 个 56+97+07
3124+97+07\02\567
。。
等几十条数据,要求:
1》编写程序,从out.txt中读取内容,经过处理后,显示效果(每行10组数据)如下:10105 10106 10108 10115 10116 10118 10135 10136 10138 10145
10146 10148 10205 10206 10208 10215 10216 10218 10235 10236
10238 10245 10246 10248 10305 10306 10308 10315 10316 10318
10335 10336 10338 10345 10346 10348 10705 10706 10708 10715
10716 10718 10735 10736 10738 10745 10746 10748 14105 14106
14108 14115 14116 14118 14135 14136 14138 14145 14146 14148
14205 14206 14208 14215 14216 14218 14235 14236 14238 14245
14246 14248 14305 14306 14308 14315 14316 14318 14335 14336
14338 14345 14346 14348 14705 14706 14708 14715 14716 14718
14735 14736 14738 14745 14746 14748 16105 16106 16108 16115
16116 16118 16135 16136 16138 16145 16146 16148 16205 16206
16208 16215 16216 16218 16235 16236 16238 16245 16246 16248
16305 16306 16308 16315 16316 16318 16335 16336 16338 16345
16346 16348 16705 16706 16708 16715 16716 16718 16735 16736
16738 16745 16746 16748 18105 18106 18108 18115 18116 18118
18135 18136 18138 18145 18146 18148 18205 18206 18208 18215
18216 18218 18235 18236 18238 18245 18246 18248 18305 18306
18308 18315 18316 18318 18335 18336 18338 18345 18346 18348
18705 18706 18708 18715 18716 18718 18735 18736 18738 18745
18746 18748 20105 20106 20108 20115 20116 20118 20135 20136
20138 20145 20146 20148 20205 20206 20208 20215 20216 20218
20235 20236 20238 20245 20246 20248 20305 20306 20308 20315
20316 20318 20335 20336 20338 20345 20346 20348 20705 20706
20708 20715 20716 20718 20735 20736 20738 20745 20746 20748
24105 24106 24108 24115 24116 24118 24135 24136 24138 24145
24146 24148 24205 24206 24208 24215 24216 24218 24235 24236
24238 24245 24246 24248 24305 24306 24308 24315 24316 24318
24335 24336 24338 24345 24346 24348 24705 24706 24708 24715
24716 24718 24735 24736 24738 24745 24746 24748 26105 26106
26108 26115 26116 26118 26135 26136 26138 26145 26146 26148
26205 26206 26208 26215 26216 26218 26235 26236 26238 26245
26246 26248 26305 26306 26308 26315 26316 26318 26335 26336
26338 26345 26346 26348 26705 26706 26708 26715 26716 26718
26735 26736 26738 26745 26746 26748 28105 28106 28108 28115
28116 28118 28135 28136 28138 28145 28146 28148 28205 28206
28208 28215 28216 28218 28235 28236 28238 28245 28246 28248
28305 28306 28308 28315 28316 28318 28335 28336 28338 28345
28346 28348 28705 28706 28708 28715 28716 28718 28735 28736
28738 28745 28746 28748 30105 30106 30108 30115 30116 30118
30135 30136 30138 30145 30146 30148 30205 30206 30208 30215
30216 30218 30235 30236 30238 30245 30246 30248 30305 30306
30308 30315 30316 30318 30335 30336 30338 30345 30346 30348
30705 30706 30708 30715 30716 30718 30735 30736 30738 30745
30746 30748 34105 34106 34108 34115 34116 34118 34135 34136
34138 34145 34146 34148 34205 34206 34208 34215 34216 34218
34235 34236 34238 34245 34246 34248 34305 34306 34308 34315
34316 34318 34335 34336 34338 34345 34346 34348 34705 34706
34708 34715 34716 34718 34735 34736 34738 34745 34746 34748
36105 36106 36108 36115 36116 36118 36135 36136 36138 36145
36146 36148 36205 36206 36208 36215 36216 36218 36235 36236
36238 36245 36246 36248 36305 36306 36308 36315 36316 36318
36335 36336 36338 36345 36346 36348 36705 36706 36708 36715
36716 36718 36735 36736 36738 36745 36746 36748 38105 38106
38108 38115 38116 38118 38135 38136 38138 38145 38146 38148
38205 38206 38208 38215 38216 38218 38235 38236 38238 38245
38246 38248 38305 38306 38308 38315 38316 38318 38335 38336
38338 38345 38346 38348 38705 38706 38708 38715 38716 38718
38735 38736 38738 38745 38746 38748 70105 70106 70108 70115
70116 70118 70135 70136 70138 70145 70146 70148 70205 70206
70208 70215 70216 70218 70235 70236 70238 70245 70246 70248
70305 70306 70308 70315 70316 70318 70335 70336 70338 70345
70346 70348 70705 70706 70708 70715 70716 70718 70735 70736
70738 70745 70746 70748 74105 74106 74108 74115 74116 74118
74135 74136 74138 74145 74146 74148 74205 74206 74208 74215
74216 74218 74235 74236 74238 74245 74246 74248 74305 74306
74308 74315 74316 74318 74335 74336 74338 74345 74346 74348
74705 74706 74708 74715 74716 74718 74735 74736 74738 74745
74746 74748 76105 76106 76108 76115 76116 76118 76135 76136
76138 76145 76146 76148 76205 76206 76208 76215 76216 76218
76235 76236 76238 76245 76246 76248 76305 76306 76308 76315
76316 76318 76335 76336 76338 76345 76346 76348 76705 76706
76708 76715 76716 76718 76735 76736 76738 76745 76746 76748
78105 78106 78108 78115 78116 78118 78135 78136 78138 78145
78146 78148 78205 78206 78208 78215 78216 78218 78235 78236
78238 78245 78246 78248 78305 78306 78308 78315 78316 78318
78335 78336 78338 78345 78346 78348 78705 78706 78708 78715
78716 78718 78735 78736 78738 78745 78746 7874856570 56577 56590 56597 56670 56677 56690 56697 57570 57577
57590 57597 57670 57677 57690 57697 59570 59577 59590 59597
59670 59677 59690 59697 66570 66577 66590 66597 66670 66677
66690 66697 67570 67577 67590 67597 67670 67677 67690 67697
69570 69577 69590 69597 69670 69677 69690 69697 76570 76577
76590 76597 76670 76677 76690 76697 77570 77577 77590 77597
77670 77677 77690 77697 79570 79577 79590 79597 79670 79677
79690 79697 86570 86577 86590 86597 86670 86677 86690 86697
87570 87577 87590 87597 87670 87677 87690 87697 89570 89577
89590 89597 89670 89677 89690 89697 96570 96577 96590 96597
96670 96677 96690 96697 97570 97577 97590 97597 97670 97677
97690 97697 99570 99577 99590 99597 99670 99677 99690 9969717005 17006 17007 17025 17026 17027 17705 17706 17707 17725
17726 17727 19005 19006 19007 19025 19026 19027 19705 19706
19707 19725 19726 19727 27005 27006 27007 27025 27026 27027
27705 27706 27707 27725 27726 27727 29005 29006 29007 29025
29026 29027 29705 29706 29707 29725 29726 29727 37005 37006
37007 37025 37026 37027 37705 37706 37707 37725 37726 37727
39005 39006 39007 39025 39026 39027 39705 39706 39707 39725
39726 39727 47005 47006 47007 47025 47026 47027 47705 47706
47707 47725 47726 47727 49005 49006 49007 49025 49026 49027
49705 49706 49707 49725 49726 49727注:相当于一条信息分成5部分,每部分有若干个数字,这部分中的每个数字与剩余部分中的每个数字组成一个5位数。
如:01、23、45、67、89,处理后应显示:
最好用正则表达式,去掉数字外的其他字符。02468 02469 02478 02479 02568 02569 02578 02579 03468 03469
03478 03479 03568 03569 03578 03579 12468 12469 12478 12479
12568 12569 12578 12579 13468 13469 13478 13479 13568 13569
13578 13579

解决方案 »

  1.   

    /*out.txt内容:
    1237/0468/1237..0143*685
    78569 十769 个 56+97+07
    3124+97+07\02\567
     */package myio;import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.Arrays;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;public class ResolveFile {
    public static void main(String[] args) {
    resolveFile("c:/out.txt");
    } public static void resolveFile(String fileName) {
    BufferedReader br = null;
    try {
    br = new BufferedReader(new FileReader(fileName));
    String sourceString = null;
    String regex = "(\\d+)\\s*(?:[^\\d]+)\\s*(\\d+)\\s*(?:[^\\d]+)\\s*(\\d+)\\s*(?:[^\\d]+)\\s*(\\d+)\\s*(?:[^\\d]+)\\s*(\\d+)";
    Matcher matcher = null;
    Pattern pattern = Pattern.compile(regex);
    while ((sourceString = br.readLine()) != null) {
    matcher = pattern.matcher(sourceString);
    if (matcher.find()) {// 找到
    char[][] a = { matcher.group(1).toCharArray(),
    matcher.group(2).toCharArray(),
    matcher.group(3).toCharArray(),
    matcher.group(4).toCharArray(),
    matcher.group(5).toCharArray() };
    // 按规则操作解释出来的二维字符数组
    display(a);
    }
    }
    } catch (IOException e) {
    } finally {
    if (br != null)
    try {
    br.close();
    } catch (IOException e) {
    throw new RuntimeException(e);
    }
    }
    }
    static void display(char[][] a) {
    for (int i = 0; i < a.length; i++)
    Arrays.sort(a[i]);
    int counter = 10;
    for (int row0 = 0; row0 < a[0].length; row0++)
    for (int row1 = 0; row1 < a[1].length; row1++)
    for (int row2 = 0; row2 < a[2].length; row2++)
    for (int row3 = 0; row3 < a[3].length; row3++)
    for (int row4 = 0; row4 < a[4].length; row4++) {
    System.out.print("" + a[0][row0] + a[1][row1]
    + a[2][row2] + a[3][row3] + a[4][row4]
    + "  ");
    if (++counter % 10 == 0) {
    counter = 0;
    System.out.println();
    }
    }
    System.out.println("\n\n"); }}
    /*output:
    10105  10106  10108  10115  10116  10118  10135  10136  10138  10145  
    10146  10148  10205  10206  10208  10215  10216  10218  10235  10236  
    10238  10245  10246  10248  10305  10306  10308  10315  10316  10318  
    10335  10336  10338  10345  10346  10348  10705  10706  10708  10715  
    10716  10718  10735  10736  10738  10745  10746  10748  14105  14106  
    14108  14115  14116  14118  14135  14136  14138  14145  14146  14148  
    14205  14206  14208  14215  14216  14218  14235  14236  14238  14245  
    14246  14248  14305  14306  14308  14315  14316  14318  14335  14336  
    14338  14345  14346  14348  14705  14706  14708  14715  14716  14718  
    14735  14736  14738  14745  14746  14748  16105  16106  16108  16115  
    16116  16118  16135  16136  16138  16145  16146  16148  16205  16206  
    16208  16215  16216  16218  16235  16236  16238  16245  16246  16248  
    16305  16306  16308  16315  16316  16318  16335  16336  16338  16345  
    16346  16348  16705  16706  16708  16715  16716  16718  16735  16736  
    16738  16745  16746  16748  18105  18106  18108  18115  18116  18118  
    18135  18136  18138  18145  18146  18148  18205  18206  18208  18215  
    18216  18218  18235  18236  18238  18245  18246  18248  18305  18306  
    18308  18315  18316  18318  18335  18336  18338  18345  18346  18348  
    18705  18706  18708  18715  18716  18718  18735  18736  18738  18745  
    18746  18748  20105  20106  20108  20115  20116  20118  20135  20136  
    20138  20145  20146  20148  20205  20206  20208  20215  20216  20218  
    20235  20236  20238  20245  20246  20248  20305  20306  20308  20315  
    20316  20318  20335  20336  20338  20345  20346  20348  20705  20706  
    20708  20715  20716  20718  20735  20736  20738  20745  20746  20748  
    24105  24106  24108  24115  24116  24118  24135  24136  24138  24145  
    24146  24148  24205  24206  24208  24215  24216  24218  24235  24236  
    24238  24245  24246  24248  24305  24306  24308  24315  24316  24318  
    24335  24336  24338  24345  24346  24348  24705  24706  24708  24715  
    24716  24718  24735  24736  24738  24745  24746  24748  26105  26106  
    26108  26115  26116  26118  26135  26136  26138  26145  26146  26148  
    26205  26206  26208  26215  26216  26218  26235  26236  26238  26245  
    26246  26248  26305  26306  26308  26315  26316  26318  26335  26336  
    26338  26345  26346  26348  26705  26706  26708  26715  26716  26718  
    26735  26736  26738  26745  26746  26748  28105  28106  28108  28115  
    28116  28118  28135  28136  28138  28145  28146  28148  28205  28206  
    28208  28215  28216  28218  28235  28236  28238  28245  28246  28248  
    28305  28306  28308  28315  28316  28318  28335  28336  28338  28345  
    28346  28348  28705  28706  28708  28715  28716  28718  28735  28736  
    28738  28745  28746  28748  30105  30106  30108  30115  30116  30118  
    30135  30136  30138  30145  30146  30148  30205  30206  30208  30215  
    30216  30218  30235  30236  30238  30245  30246  30248  30305  30306  
    30308  30315  30316  30318  30335  30336  30338  30345  30346  30348  
    30705  30706  30708  30715  30716  30718  30735  30736  30738  30745  
    30746  30748  34105  34106  34108  34115  34116  34118  34135  34136  
    34138  34145  34146  34148  34205  34206  34208  34215  34216  34218  
    34235  34236  34238  34245  34246  34248  34305  34306  34308  34315  
    34316  34318  34335  34336  34338  34345  34346  34348  34705  34706  
    34708  34715  34716  34718  34735  34736  34738  34745  34746  34748  
    36105  36106  36108  36115  36116  36118  36135  36136  36138  36145  
    36146  36148  36205  36206  36208  36215  36216  36218  36235  36236  
    36238  36245  36246  36248  36305  36306  36308  36315  36316  36318  
    36335  36336  36338  36345  36346  36348  36705  36706  36708  36715  
    36716  36718  36735  36736  36738  36745  36746  36748  38105  38106  
    38108  38115  38116  38118  38135  38136  38138  38145  38146  38148  
    38205  38206  38208  38215  38216  38218  38235  38236  38238  38245  
    38246  38248  38305  38306  38308  38315  38316  38318  38335  38336  
    38338  38345  38346  38348  38705  38706  38708  38715  38716  38718  
    38735  38736  38738  38745  38746  38748  70105  70106  70108  70115  
    70116  70118  70135  70136  70138  70145  70146  70148  70205  70206  
    70208  70215  70216  70218  70235  70236  70238  70245  70246  70248  
    70305  70306  70308  70315  70316  70318  70335  70336  70338  70345  
    70346  70348  70705  70706  70708  70715  70716  70718  70735  70736  
    70738  70745  70746  70748  74105  74106  74108  74115  74116  74118  
    74135  74136  74138  74145  74146  74148  74205  74206  74208  74215  
    74216  74218  74235  74236  74238  74245  74246  74248  74305  74306  
    74308  74315  74316  74318  74335  74336  74338  74345  74346  74348  
    74705  74706  74708  74715  74716  74718  74735  74736  74738  74745  
    74746  74748  76105  76106  76108  76115  76116  76118  76135  76136  
    76138  76145  76146  76148  76205  76206  76208  76215  76216  76218  
    76235  76236  76238  76245  76246  76248  76305  76306  76308  76315  
    76316  76318  76335  76336  76338  76345  76346  76348  76705  76706  
    76708  76715  76716  76718  76735  76736  76738  76745  76746  76748  
    78105  78106  78108  78115  78116  78118  78135  78136  78138  78145  
    78146  78148  78205  78206  78208  78215  78216  78218  78235  78236  
    78238  78245  78246  78248  78305  78306  78308  78315  78316  78318  
    78335  78336  78338  78345  78346  78348  78705  78706  78708  78715  
    78716  78718  78735  78736  78738  78745  78746  78748  
    56570  56577  56590  56597  56670  56677  56690  56697  57570  57577  
    57590  57597  57670  57677  57690  57697  59570  59577  59590  59597  
    59670  59677  59690  59697  66570  66577  66590  66597  66670  66677  
    66690  66697  67570  67577  67590  67597  67670  67677  67690  67697  
    69570  69577  69590  69597  69670  69677  69690  69697  76570  76577  
    76590  76597  76670  76677  76690  76697  77570  77577  77590  77597  
    77670  77677  77690  77697  79570  79577  79590  79597  79670  79677  
    79690  79697  86570  86577  86590  86597  86670  86677  86690  86697  
    87570  87577  87590  87597  87670  87677  87690  87697  89570  89577  
    89590  89597  89670  89677  89690  89697  96570  96577  96590  96597  
    96670  96677  96690  96697  97570  97577  97590  97597  97670  97677  
    97690  97697  99570  99577  99590  99597  99670  99677  99690  99697  17005  17006  17007  17025  17026  17027  17705  17706  17707  17725  
    17726  17727  19005  19006  19007  19025  19026  19027  19705  19706  
    19707  19725  19726  19727  27005  27006  27007  27025  27026  27027  
    27705  27706  27707  27725  27726  27727  29005  29006  29007  29025  
    29026  29027  29705  29706  29707  29725  29726  29727  37005  37006  
    37007  37025  37026  37027  37705  37706  37707  37725  37726  37727  
    39005  39006  39007  39025  39026  39027  39705  39706  39707  39725  
    39726  39727  47005  47006  47007  47025  47026  47027  47705  47706  
    47707  47725  47726  47727  49005  49006  49007  49025  49026  49027  
    49705  49706  49707  49725  49726  49727  
     */
      

  2.   

    String regex = "(\\d+)\\s*(?:[^\\d]+)\\s*(\\d+)\\s*(?:[^\\d]+)\\s*(\\d+)\\s*(?:[^\\d]+)\\s*(\\d+)\\s*(?:[^\\d]+)\\s*(\\d+)";
      

  3.   

    5次循环。用递归吧: static int t = 0;

    public static void main(String[] args) {
    String str = "1237/0468/1237..0143*685";
    String[] str_2 = str.split("[^\\d]+");
    int[][] n = new int[str_2.length][];
    for(int i = 0; i < n.length;i++) {
    n[i] = new int[str_2[i].length()];
    for(int j = 0;j<n[i].length;j++) {
    n[i][j] =Integer.parseInt(str_2[i].substring(j, j+1));
    }
    Arrays.sort(n[i]);
    }
    out(n,0,"");
    }

    public static void out(int[][] n,int i,String str) {
    if(i==n.length-1) {
    for(int k = 0; k < n[i].length;k++) {
    System.out.print(str+n[i][k]+"  ");
    t++;
    if(t==10) {
    System.out.println();
    t = 0;
    }
    }
    }
    else {
    for(int k = 0; k < n[i].length;k++) {
    String test = str+n[i][k];
    out(n,i+1,test);
    }
    }
    }
      

  4.   

    楼主就这一个问题发N次有意思么?真相:http://forum.csdn.net/PointForum/Forum/UserTopicList.aspx?user=wjsdwbw
      

  5.   

    看了14L,发现LZ你真TMD的多分啊,同样的问题发那么多贴
      

  6.   

    恩,这个类似的帖子见过很多次
    从以前的回复中把代码找过来修改一下
    http://topic.csdn.net/u/20110608/22/9ff572b2-5bfa-44b6-8546-e4e41cc0f2b8.htmlLZ是只会鱼儿不会渔,LZ好好看看这个回复和以前我给你的回复,基本代码不变,只是稍微做些非数字判断的修改,LZ该思取长进了,不要以为自己分多就每次都求人,总有一天你有求不到人的时候的,自己学会就是自己的本事,听不听在LZ自己了import java.io.*;
    import java.util.*;
    public class Test {
        public static void main(String[] args) {
            try {
                BufferedReader br = new BufferedReader(new InputStreamReader(
                                    new FileInputStream("out.txt")));
                String buf;
                while ((buf=br.readLine()) != null) {
                    if (!buf.matches("(\\D*\\d+\\D*)+")) continue;
                    buf = buf.replaceAll("^\\D+(.*)", "$1");
                    String[] data = buf.split("\\D+");
                    char[][] c = new char[data.length][];
                    for (int i=0; i<c.length; i++) {
                        c[i] = data[i].toCharArray();
                        Arrays.sort(c[i]);
                    }
                    doCombine(c);
                    System.out.println();
                }
                br.close();
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }    public static void doCombine(char[][] c) {
            int[] idx = new int[c.length];
            Arrays.fill(idx, 0);
            List<String> result = new ArrayList<String>();
            while (true) {
                StringBuilder sb = new StringBuilder();
                for (int i=0; i<idx.length; i++) {
                    sb.append(c[i][idx[i]]);
                }
                result.add(sb.toString());
                idx[idx.length-1]++;
                for (int i=idx.length-1; i>0; i--) {
                    if (idx[i] == c[i].length) {
                        idx[i] = 0;
                        idx[i-1]++;
                    }
                }
                if (idx[0] == c[0].length) {break;}
            }
            for (int i=0; i<result.size(); i++) {
                System.out.printf("%s ", result.get(i));
                if ((i+1)%10 == 0) {System.out.println();}
            }
            System.out.println();
        }
    }
      

  7.   

    正责我不太会。不用正责也写出来了。
    五次循环这要求四楼也没合格。
    StringBuffer sb = new StringBuffer(sourceString);
    for(int i=0;i<sourceString.length();i++){
       if(number.indexOf(String.valueOf(sourceString.charAt(i))) == -1){
    sb.deleteCharAt(i).insert(i, " ");
        }
    }
    StringTokenizer st = new StringTokenizer(sb.toString());
    char[][] source = new char[5][];
    int index = 0;
    while(st.hasMoreElements()){
        char[] c = st.nextElement().toString().toCharArray();
        Arrays.sort(c);
        source[index++] = c;
    }