假设有一组数据
1 2 4
2 3 5
4 5 6
3 4 2怎么获取字符串使
a[]={1,2,4,3}
b[]={2,3,54,}
c[]={4,5,6,2}求大神帮忙

解决方案 »

  1.   

    for example
    String s[][] = {
        {"1","2","4"},
        {"2","3","5"},
        {"4","5","6"},
        {"3","4","2"}
    }
    String[][] sa = new String[s[0].length][s.length]; //矩阵行列转换
    for (int i=0; i<s.length;i++) {
        for (int j=0; j<s[i].length; j++) {
            sa[j][i] = s[i][j];
        }
    }
    String[] a = sa[0];
    String[] b = sa[1];
    String[] c = sa[2];
    System.out.println(Arrays.toString(a));
    System.out.println(Arrays.toString(b));
    System.out.println(Arrays.toString(c));
      

  2.   

    我还是说出实际情况吧
            BufferedReader br = new BufferedReader(new InputStreamReader(  
                     new FileInputStream("wcc.txt")));  
    for (String line = br.readLine(); line != null; line = br.readLine()) {  
    System.out.println(line);  
            }  
            br.close();  
    数据是从wcc.txt读出来的
    wcc:
    1 1 101
    1 2 104
    2 3 103
    3 2 104
    2 2 102
    3 3 103
    4 4 105
    3 1 101
    2 3 103现在求二三列各种组合+次数
    比如二三列:   输出:
    1 101  (1 1 101和3 1 101) 所以输出 2        
    2 104    输出 2
    3 103    输出 3
    。求大神帮忙
      

  3.   

    最后输出结果:
    1 101 2
    2 104 2
    3 103 3

    wcc.txt的行数可变
      

  4.   

    for (String line = br.readLine(); line != null; line = br.readLine()) 改成 for (String line = br.readLine(); line != null;) 
      

  5.   


    List<String> list = new ArrayList<String>();
    Map<String, Integer> map = new HashMap<String,Integer>();

    BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("e:/wcc.txt")));
    for (String line = br.readLine(); line != null; line = br.readLine()) {
    list.add(line.substring(2));
    }
    br.close();

    for (String key : list) {
    if (map.containsKey(key)) {
    map.put(key, map.get(key) + 1);
    } else {
    map.put(key, 1);
    }
    }
    for (String key : list) {
    System.out.println(key + " " + map.get(key));
    }
      

  6.   

    wcc.txt的行数可变的话,更简单了,O(n)就可以了。
    Map<String, Integer> map = new TreeMap<String,Integer>();

    BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("e:/wcc.txt")));
    for (String line = br.readLine(); line != null; line = br.readLine()) {
    String key = line.substring(2);
    if (map.containsKey(key)) {
    map.put(key, map.get(key) + 1);
    } else {
    map.put(key, 1);
    }
    }
    br.close();

    for (String key : map.keySet()) {
    System.out.println(key + " " + map.get(key));
    }
      

  7.   


    根据wcc.txt最后输出:
    输出:
    1 101 2
    2 104 2
    3 103 3
    2 102 1
    4 105 1
      

  8.   

    for example
    import java.util.*;
    public class Test {
        public static void main(String[] args) throws Throwable {
            List<String[]> data = new ArrayList<String[]>();
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("wcc.txt")));   
            for (String line = br.readLine(); line != null; line = br.readLine()) {   
                if (! line.matches("\\d+(\\s+\\d+){2,}\\s*")) continue;
                String[] s1 = line.split("\\s+");
                boolean found = false;
                for (String[] s2 : data) {
                    if (s1[1].equals(s2[0]) && s1[2].equals(s2[1])) {
                        s2[2] = String.valueOf(Integer.valueOf(s2[2]) + 1);
                        found = true;
                        break;
                    }
                }
                if (! found) {
                    for (int i=0; i<s1.length-1; i++) {
                        s1[i] = s1[i+1];
                    }
                    s1[s1.length-1] = "1";
                    data.add(s1);
                }
            }   
            br.close();        for (String[] sa : data) {
                for (String s : sa) {
                    System.out.printf("%s ", s);
                }
                System.out.println();
            }
        }
    }