题目:
文件dingwei.txt中有多条内容。
如:
编写程序,读出文章内容,并对数据进行处理,输出必须与下面一致。
123/2789/6789
0247/134568/56789
23479/013578/135678
000 001 002 003 004 005 010 011 012 013
014 015 030 031 032 033 034 035 040 041
042 043 044 045 050 051 052 053 054 055
060 061 062 063 064 065 400 401 402 403
404 405 410 411 412 413 414 415 430 431
432 433 434 435 440 441 442 443 444 445
450 451 452 453 454 455 460 461 462 463
464 465 500 501 502 503 504 505 510 511
512 513 514 515 530 531 532 533 534 535
540 541 542 543 544 545 550 551 552 553
554 555 560 561 562 563 564 565 600 601
602 603 604 605 610 611 612 613 614 615
630 631 632 633 634 635 640 641 642 643
644 645 650 651 652 653 654 655 660 661
662 663 664 665 700 701 702 703 704 705
710 711 712 713 714 715 730 731 732 733
734 735 740 741 742 743 744 745 750 751
752 753 754 755 760 761 762 763 764 765
800 801 802 803 804 805 810 811 812 813
814 815 830 831 832 833 834 835 840 841
842 843 844 845 850 851 852 853 854 855
860 861 862 863 864 865 900 901 902 903
904 905 910 911 912 913 914 915 930 931
932 933 934 935 940 941 942 943 944 945
950 951 952 953 954 955 960 961 962 963
964 965100 101 102 103 104 120 121 122 123 124
170 171 172 173 174 190 191 192 193 194
300 301 302 303 304 320 321 322 323 324
370 371 372 373 374 390 391 392 393 394
500 501 502 503 504 520 521 522 523 524
570 571 572 573 574 590 591 592 593 594
600 601 602 603 604 620 621 622 623 624
670 671 672 673 674 690 691 692 693 694
800 801 802 803 804 820 821 822 823 824
870 871 872 873 874 890 891 892 893 894
900 901 902 903 904 920 921 922 923 924
970 971 972 973 974 990 991 992 993 994020 022 024 029 040 042 044 049 060 062
064 069 090 092 094 099 120 122 124 129
140 142 144 149 160 162 164 169 190 192
194 199 520 522 524 529 540 542 544 549
560 562 564 569 590 592 594 599 620 622
624 629 640 642 644 649 660 662 664 669
690 692 694 699 820 822 824 829 840 842
844 849 860 862 864 869 890 892 894 899即:输出每条语句中,没出现的数字。
123/2789/6789 ----------> 输出0456789/013456/012345
0247/134568/56789-------->输出135689/0279/01234
23479/013578/135678------>输出01568/2469/0249

解决方案 »

  1.   

    又是类似的问题,在上个问题答案的基础上改一下不就行了吗?无语了
    http://topic.csdn.net/u/20110608/22/9ff572b2-5bfa-44b6-8546-e4e41cc0f2b8.htmlclass Test {
        public static void main(String[] args) {
            try {
                final char[] dig = {'0','1','2','3','4','5','6','7','8','9'};
                String filename = "dingwei.txt";
                BufferedReader br = new BufferedReader(new InputStreamReader(
                                    new FileInputStream(filename)));
                for (String buf = br.readLine(); buf != null; buf = br.readLine()) {
                    String[] data = buf.split("/");
                    char[][] c = new char[data.length][];
                    for (int i=0; i<c.length; i++) {
                        c[i] = data[i].toCharArray();
                        char[] cc = new char[dig.length-c[i].length];
                        for (int j=0, k=0; j<dig.length; j++) {
                            if (Arrays.binarySearch(c[i], dig[j]) < 0) {
                                cc[k++] = dig[j];
                            }
                        }
                        c[i] = cc;
                    }
                    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();
        }
    }
      

  2.   

    LZ多半不会结贴了 因为他连回帖都不看 LS的大虾下次就别废这功夫了
      

  3.   

    这是从上个答复的帖子里拷贝过来改一改的,没花什么功夫。只是觉得LZ不上进,不会学以致用。
    都说授人鱼不如授人渔,对LZ无语了。
      

  4.   

    上面两位批评的对,我一定努力的改进。
    请教下阿宝,你写的下面这个方法看不太明白,详细注释下好吗?拜托!!!
    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();
        }
    小弟是自己业余自学java,请各位帮帮小弟。