文件out.txt中,有如下内容:
045689、123579、045689
012389、256789、124567
0123489、13456789、0123489
0123479、0123479、0123479
234789、01234789、234789
01234、0123458、01234789
056789、01234568、12345689
123489、124569、124589
。。
等几十条数据,要求:
2》编写程序,从out.txt中读取内容,经过处理后,显示
效果(每行10组数据)如下:
101 102 103 107 141 142 143 147 161 162 
163 167 181 182 183 187 201 202 203 207 
241 242 243 247 261 262 263 267 281 282 
283 287 301 302 303 307 341 342 343 347 
361 362 363 367 381 382 383 387 701 702 
703 707 741 742 743 747 761 762 763 767 
781 782 783 787 400 403 408 409 410 413 418 419 430 433 
438 439 440 443 448 449 500 503 508 509 
510 513 518 519 530 533 538 539 540 543 
548 549 600 603 608 609 610 613 618 619 
630 633 638 639 640 643 648 649 700 703 
708 709 710 713 718 719 730 733 738 739 
740 743 748 749 505 506 507 525 526 527 605 606 607 625 
626 627 705 706 707 725 726 727 555 556 558 565 566 568 585 586 588 655 
656 658 665 666 668 685 686 688 855 856 
858 865 866 868 885 886 888 050 051 055 056 060 061 065 066 150 151 
155 156 160 161 165 166 550 551 555 556 
560 561 565 566 650 651 655 656 660 661 
665 666 565 566 575 576 595 596 665 666 675 676 
695 696 765 766 775 776 795 796 865 866 
875 876 895 896 965 966 975 976 995 996 
170 177 190 197 270 277 290 297 370 377 
390 397 470 477 490 497 000 003 006 007 030 033 036 037 070 073 
076 077 080 083 086 087 500 503 506 507 
530 533 536 537 570 573 576 577 580 583 
586 587 600 603 606 607 630 633 636 637 
670 673 676 677 680 683 686 687 700 703 
706 707 730 733 736 737 770 773 776 777 
780 783 786 787 
注:相当于一条信息分成3部分,每部分有若干个数字,先
将每部分的数字转化为0~9中不没出现的数字,如:03456789、01256789、01234789 ----转化后为:12、34、56,然后每部分的每个数字与另两部分中的每个数字组成一个3位数。处理后应显示:135 136 145 146 235 236 245 246 。

解决方案 »

  1.   

    文件out.txt中,有如下内容:
    045689、123579、045689
    012389、256789、124567
    0123489、13456789、0123489
    0123479、0123479、0123479
    234789、01234789、234789
    01234、0123458、01234789
    056789、01234568、12345689
    123489、124569、124589
    。。
    等几十条数据,要求:
    2》编写程序,从out.txt中读取内容,经过处理后,显示
    效果(每行10组数据)如下:
    101 102 103 107 141 142 143 147 161 162  
    163 167 181 182 183 187 201 202 203 207  
    241 242 243 247 261 262 263 267 281 282  
    283 287 301 302 303 307 341 342 343 347  
    361 362 363 367 381 382 383 387 701 702  
    703 707 741 742 743 747 761 762 763 767  
    781 782 783 787  400 403 408 409 410 413 418 419 430 433  
    438 439 440 443 448 449 500 503 508 509  
    510 513 518 519 530 533 538 539 540 543  
    548 549 600 603 608 609 610 613 618 619  
    630 633 638 639 640 643 648 649 700 703  
    708 709 710 713 718 719 730 733 738 739  
    740 743 748 749  505 506 507 525 526 527 605 606 607 625  
    626 627 705 706 707 725 726 727  555 556 558 565 566 568 585 586 588 655  
    656 658 665 666 668 685 686 688 855 856  
    858 865 866 868 885 886 888  050 051 055 056 060 061 065 066 150 151  
    155 156 160 161 165 166 550 551 555 556  
    560 561 565 566 650 651 655 656 660 661  
    665 666  565 566 575 576 595 596 665 666 675 676  
    695 696 765 766 775 776 795 796 865 866  
    875 876 895 896 965 966 975 976 995 996  
    170 177 190 197 270 277 290 297 370 377  
    390 397 470 477 490 497  000 003 006 007 030 033 036 037 070 073  
    076 077 080 083 086 087 500 503 506 507  
    530 533 536 537 570 573 576 577 580 583  
    586 587 600 603 606 607 630 633 636 637  
    670 673 676 677 680 683 686 687 700 703  
    706 707 730 733 736 737 770 773 776 777  
    780 783 786 787  
    注:相当于一条信息分成3部分,每部分有若干个数字,先
    将每部分的数字转化为0~9中不没出现的数字,如:03456789、01256789、01234789 ----转化后为:12、34、56,然后每部分的每个数字与另两部分中的每个数字组成一个3位数。处理后应显示:135 136 145 146 235 236 245 246 
      

  2.   

    文件out.txt中,有如下内容:
    045689、123579、045689
    012389、256789、124567
    0123489、13456789、0123489
    0123479、0123479、0123479
    234789、01234789、234789
    01234、0123458、01234789
    056789、01234568、12345689
    123489、124569、124589
    。。
    等几十条数据,要求:
    2》编写程序,从out.txt中读取内容,经过处理后,显示
    效果(每行10组数据)如下:
    101 102 103 107 141 142 143 147 161 162  
    163 167 181 182 183 187 201 202 203 207  
    241 242 243 247 261 262 263 267 281 282  
    283 287 301 302 303 307 341 342 343 347  
    361 362 363 367 381 382 383 387 701 702  
    703 707 741 742 743 747 761 762 763 767  
    781 782 783 787  400 403 408 409 410 413 418 419 430 433  
    438 439 440 443 448 449 500 503 508 509  
    510 513 518 519 530 533 538 539 540 543  
    548 549 600 603 608 609 610 613 618 619  
    630 633 638 639 640 643 648 649 700 703  
    708 709 710 713 718 719 730 733 738 739  
    740 743 748 749  505 506 507 525 526 527 605 606 607 625  
    626 627 705 706 707 725 726 727  555 556 558 565 566 568 585 586 588 655  
    656 658 665 666 668 685 686 688 855 856  
    858 865 866 868 885 886 888  050 051 055 056 060 061 065 066 150 151  
    155 156 160 161 165 166 550 551 555 556  
    560 561 565 566 650 651 655 656 660 661  
    665 666  565 566 575 576 595 596 665 666 675 676  
    695 696 765 766 775 776 795 796 865 866  
    875 876 895 896 965 966 975 976 995 996  
    170 177 190 197 270 277 290 297 370 377  
    390 397 470 477 490 497  000 003 006 007 030 033 036 037 070 073  
    076 077 080 083 086 087 500 503 506 507  
    530 533 536 537 570 573 576 577 580 583  
    586 587 600 603 606 607 630 633 636 637  
    670 673 676 677 680 683 686 687 700 703  
    706 707 730 733 736 737 770 773 776 777  
    780 783 786 787  
    注:相当于一条信息分成3部分,每部分有若干个数字,先
    将每部分的数字转化为0~9中不没出现的数字,如:03456789、01256789、01234789 ----转化后为:12、34、56,然后每部分的每个数字与另两部分中的每个数字组成一个3位数。处理后应显示:135 136 145 146 235 236 245 246 。
      

  3.   

    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.HashSet;
    import java.util.List;
    import java.util.Set;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class ResolveFile {
        static int counter = 10;    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*(?:、)\\s*(\\d+)\\s*(?:、)\\s*(\\d+)";
        Matcher matcher = null;
        Pattern pattern = Pattern.compile(regex);
        while ((sourceString = br.readLine()) != null) {
    matcher = pattern.matcher(sourceString);
    if (matcher.find()) {// 找到
        char[] ch1 = matcher.group(1).toCharArray();
        char[] ch2 = matcher.group(2).toCharArray();
        char[] ch3 = matcher.group(3).toCharArray();
       // Arrays.sort(ch1);  Arrays.sort(ch2);   Arrays.sort(ch3);改为下面一行
        ch1 = getComplement(ch1); ch2 = getComplement(ch2); ch3 = getComplement(ch3);
        for (int i = 0; i < ch1.length; i++)
    for (int j = 0; j < ch2.length; j++)
        for (int k = 0; k < ch3.length; k++) {
    System.out.print("" + ch1[i] + ch2[j]
    + ch3[k] + " ");
    if (++counter % 10 == 0)
        System.out.println();
        }
    }
    System.out.println("\n\n");
    counter = 0;
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        if (br != null)
    try {
        br.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    }
        }
        
        public  static char[] getComplement(char[] ch){//添加求补方法
    Set<Character> set =  new  HashSet();
    for(char c : ch) set.add(c);
    List<Character> list = new ArrayList();
    for(char i='0';i<='9';i++)
    if(!set.contains(i))list.add(i);
    char[] temp = new char[list.size()];
    for(int i=0; i<list.size();i++)temp[i] = list.get(i);
    return temp;
        }
    }
    /*
    101 102 103 107 141 142 143 147 161 162 
    163 167 181 182 183 187 201 202 203 207 
    241 242 243 247 261 262 263 267 281 282 
    283 287 301 302 303 307 341 342 343 347 
    361 362 363 367 381 382 383 387 701 702 
    703 707 741 742 743 747 761 762 763 767 
    781 782 783 787 
    400 403 408 409 410 413 418 419 430 433 
    438 439 440 443 448 449 500 503 508 509 
    510 513 518 519 530 533 538 539 540 543 
    548 549 600 603 608 609 610 613 618 619 
    630 633 638 639 640 643 648 649 700 703 
    708 709 710 713 718 719 730 733 738 739 
    740 743 748 749 
    505 506 507 525 526 527 605 606 607 625 
    626 627 705 706 707 725 726 727 
    555 556 558 565 566 568 585 586 588 655 
    656 658 665 666 668 685 686 688 855 856 
    858 865 866 868 885 886 888 
    050 051 055 056 060 061 065 066 150 151 
    155 156 160 161 165 166 550 551 555 556 
    560 561 565 566 650 651 655 656 660 661 
    665 666 
    565 566 575 576 595 596 665 666 675 676 
    695 696 765 766 775 776 795 796 865 866 
    875 876 895 896 965 966 975 976 995 996 170 177 190 197 270 277 290 297 370 377 
    390 397 470 477 490 497 
    000 003 006 007 030 033 036 037 070 073 
    076 077 080 083 086 087 500 503 506 507 
    530 533 536 537 570 573 576 577 580 583 
    586 587 600 603 606 607 630 633 636 637 
    670 673 676 677 680 683 686 687 700 703 
    706 707 730 733 736 737 770 773 776 777 
    780 783 786 787 
    */
     
      

  4.   

    文件out.txt中,有如下内容:
    045689、123579、045689
    012389、256789、124567
    0123489、13456789、0123489
    0123479、0123479、0123479
    234789、01234789、234789
    01234、0123458、01234789
    056789、01234568、12345689
    123489、124569、124589
    。。
    等几十条数据,要求:
    2》编写程序,从out.txt中读取内容,经过处理后,显示
    效果(每行10组数据)如下:
    101 102 103 107 141 142 143 147 161 162   
    163 167 181 182 183 187 201 202 203 207   
    241 242 243 247 261 262 263 267 281 282   
    283 287 301 302 303 307 341 342 343 347   
    361 362 363 367 381 382 383 387 701 702   
    703 707 741 742 743 747 761 762 763 767   
    781 782 783 787   400 403 408 409 410 413 418 419 430 433   
    438 439 440 443 448 449 500 503 508 509   
    510 513 518 519 530 533 538 539 540 543   
    548 549 600 603 608 609 610 613 618 619   
    630 633 638 639 640 643 648 649 700 703   
    708 709 710 713 718 719 730 733 738 739   
    740 743 748 749   505 506 507 525 526 527 605 606 607 625   
    626 627 705 706 707 725 726 727   555 556 558 565 566 568 585 586 588 655   
    656 658 665 666 668 685 686 688 855 856   
    858 865 866 868 885 886 888   050 051 055 056 060 061 065 066 150 151   
    155 156 160 161 165 166 550 551 555 556   
    560 561 565 566 650 651 655 656 660 661   
    665 666   565 566 575 576 595 596 665 666 675 676   
    695 696 765 766 775 776 795 796 865 866   
    875 876 895 896 965 966 975 976 995 996   
    170 177 190 197 270 277 290 297 370 377   
    390 397 470 477 490 497   000 003 006 007 030 033 036 037 070 073   
    076 077 080 083 086 087 500 503 506 507   
    530 533 536 537 570 573 576 577 580 583   
    586 587 600 603 606 607 630 633 636 637   
    670 673 676 677 680 683 686 687 700 703   
    706 707 730 733 736 737 770 773 776 777   
    780 783 786 787   
    注:相当于一条信息分成3部分,每部分有若干个数字,先
    将每部分的数字转化为0~9中不没出现的数字,如:03456789、01256789、01234789 ----转化后为:12、34、56,然后每部分的每个数字与另两部分中的每个数字组成一个3位数。处理后应显示:135 136 145 146 235 236 245 246 。
      

  5.   


    在C盘下建立一个文件
    文件名:out.txt
    文件内容:(最好复制,我怀疑是你的标点符号在搞鬼)045689、123579、045689
    012389、256789、124567
    0123489、13456789、0123489
    0123479、0123479、0123479
    234789、01234789、234789
    01234、0123458、01234789
    056789、01234568、12345689
    123489、124569、124589然后就会输出你给出的效果
      

  6.   

    又是这个问题,记得以前回答过不下5次
    直接手写一个,未测试
    import java.util.*;
    class Test {
        public static void main(String[] args) throws Throwable {
            String filename = "out.txt";
            String[] dig = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
            String buf;
            List<List<String>> list = new ArrayList<List<String>>();
            while((buf=br.readLine()) != null) {
                String[] sa = buf.split("、", -1);
                if (sa.length != 3) continue;
                list.clear();
                for (String s : sa) {
                    List<String> subList = new ArrayList<String>();
                    for (String d : dig) {
                        if (!s.contains(d)) {
                            subList.add(d);
                        }
                    }
                    list.add(subList);
                }
                combine(list);
            }
            br.close();
        }     public static void combine(List<List<String>> list) {
            int[] idx = new int[list.size()];
            int count = 1;
            for (List<String> l : list) {
                count *= (l.size() == 0 ? 1 : l.size());
            }
            List<String> result = new ArrayList<String>();
            while(count > 0) {
                StringBuilder buf = new StringBuilder();
                for (int i=0; i<idx.length; i++) {
                    List<String> l = list.get(i);
                    if (l.size() > 0) {
                        buf.append(l.get(idx[i]));
                    }
                }
                result.add(buf.toString());            idx[idx.length-1]++;
                for (int i=idx.length-1; i>0; i--) {
                    if (idx[i] >= list.get(i).size()) {
                        idx[i] = 0;
                        idx[i-1]++;
                    }
                }            count--;
            }        for(int i=0; i<result.size(); i++) {
                if ((i+1)%10 == 0) {
                    System.out.println(result.get(i));
                } else {
                    System.out.printf("%s ", result.get(i));
                }
            }
        }
    }
      

  7.   

    k3108001263大侠:
    文件名:out.txt
    文件内容:(最好复制,我怀疑是你的标点符号在搞鬼)
    3124+97+07
    6705//0837//03676475..0143..0938
    567\02\567
    856*856*685
    0615---56---0156
    78569 十769 个 561578/4679/1368
    1269---0129---1367
    0369十1234个5678
    3579/5679/1268
    1237/0468/1237

    多条记录,就不行了,你试试
      

  8.   


    这一个程序可以解释 第0楼 第15楼给出的所有数据 ,如果你发现哪一个记录没有解释出来,你必须把它贴上来,注意那些分隔符, 要复制,除非你能准确区分中文英文的分隔符
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.HashSet;
    import java.util.List;
    import java.util.Set;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class ResolveFile {
        static int counter = 10;    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*(?:[/\\\\\\*+//]|---|[\\.]{2}|十|//|、)\\s*(\\d+)\\s*(?:[/\\\\\\*+//|、]|---|[\\.]{2}|个|//)\\s*(\\d+)"; 
            Matcher matcher = null;
            Pattern pattern = Pattern.compile(regex);
            while ((sourceString = br.readLine()) != null) {
            matcher = pattern.matcher(sourceString);
            if (matcher.find()) {// 找到
                char[] ch1 = matcher.group(1).toCharArray();
                char[] ch2 = matcher.group(2).toCharArray();
                char[] ch3 = matcher.group(3).toCharArray();
               // Arrays.sort(ch1);  Arrays.sort(ch2);   Arrays.sort(ch3);改为下面一行
                ch1 = getComplement(ch1); ch2 = getComplement(ch2); ch3 = getComplement(ch3);
                for (int i = 0; i < ch1.length; i++)
                for (int j = 0; j < ch2.length; j++)
                    for (int k = 0; k < ch3.length; k++) {
                    System.out.print("" + ch1[i] + ch2[j]
                        + ch3[k] + " ");
                    if (++counter % 10 == 0)
                        System.out.println();
                    }
            }
            System.out.println("\n\n");
            counter = 0;
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (br != null)
            try {
                br.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        }
        
        public  static char[] getComplement(char[] ch){//添加求补方法
        Set<Character> set =  new  HashSet<Character>();
        for(char c : ch) set.add(c);
        List<Character> list = new ArrayList<Character>();
        for(char i='0';i<='9';i++)
        if(!set.contains(i))list.add(i);
        char[] temp = new char[list.size()];
        for(int i=0; i<list.size();i++)temp[i] = list.get(i);
        return temp;    
        }
    }
      

  9.   


    要不你把正则表达式改成下面的,估计能够处理所有的你认为的分隔符,
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.HashSet;
    import java.util.List;
    import java.util.Set;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class ResolveFile {
        static int counter = 10;    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+)"; 
            Matcher matcher = null;
            Pattern pattern = Pattern.compile(regex);
            while ((sourceString = br.readLine()) != null) {
            matcher = pattern.matcher(sourceString);
            if (matcher.find()) {// 找到
                char[] ch1 = matcher.group(1).toCharArray();
                char[] ch2 = matcher.group(2).toCharArray();
                char[] ch3 = matcher.group(3).toCharArray();
               // Arrays.sort(ch1);  Arrays.sort(ch2);   Arrays.sort(ch3);改为下面一行
                ch1 = getComplement(ch1); ch2 = getComplement(ch2); ch3 = getComplement(ch3);
                for (int i = 0; i < ch1.length; i++)
                for (int j = 0; j < ch2.length; j++)
                    for (int k = 0; k < ch3.length; k++) {
                    System.out.print("" + ch1[i] + ch2[j]
                        + ch3[k] + " ");
                    if (++counter % 10 == 0)
                        System.out.println();
                    }
            }
            System.out.println("\n\n");
            counter = 0;
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (br != null)
            try {
                br.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        }
        
        public  static char[] getComplement(char[] ch){//添加求补方法
        Set<Character> set =  new  HashSet<Character>();
        for(char c : ch) set.add(c);
        List<Character> list = new ArrayList<Character>();
        for(char i='0';i<='9';i++)
        if(!set.contains(i))list.add(i);
        char[] temp = new char[list.size()];
        for(int i=0; i<list.size();i++)temp[i] = list.get(i);
        return temp;    
        }
    }
      

  10.   

    修改一下分隔符就可以了
    import java.util.*;
    class Test {
        public static void main(String[] args) throws Throwable {
            String filename = "out.txt";
            String delims = "[\\D]+"; //修改这里,可以自己追加需要的分隔符
            String[] dig = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
            String buf;
            List<List<String>> list = new ArrayList<List<String>>();
            while((buf=br.readLine()) != null) {
                String[] sa = buf.split(delims, -1);
                if (sa.length != 3) continue;
                list.clear();
                for (String s : sa) {
                    List<String> subList = new ArrayList<String>();
                    for (String d : dig) {
                        if (!s.contains(d)) {
                            subList.add(d);
                        }
                    }
                    list.add(subList);
                }
                combine(list);
            }
            br.close();
        }     public static void combine(List<List<String>> list) {
            int[] idx = new int[list.size()];
            int count = 1;
            for (List<String> l : list) {
                count *= (l.size() == 0 ? 1 : l.size());
            }
            List<String> result = new ArrayList<String>();
            while(count > 0) {
                StringBuilder buf = new StringBuilder();
                for (int i=0; i<idx.length; i++) {
                    List<String> l = list.get(i);
                    if (l.size() > 0) {
                        buf.append(l.get(idx[i]));
                    }
                }
                result.add(buf.toString());            idx[idx.length-1]++;
                for (int i=idx.length-1; i>0; i--) {
                    if (idx[i] >= list.get(i).size()) {
                        idx[i] = 0;
                        idx[i-1]++;
                    }
                }            count--;
            }        for(int i=0; i<result.size(); i++) {
                if ((i+1)%10 == 0) {
                    System.out.println(result.get(i));
                } else {
                    System.out.printf("%s ", result.get(i));
                }
            }
        }
    }