用一维数组保存二维矩阵

矩阵元素定位

http://www.nowcoder.com/questionTerminal/b8e6a46992fe4e11b2822b20561b6d94

用一维数组保存二维矩阵:

import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt();
        int[] v = new int[n*m];
        for(int i = 0; i < n*m; ++i) v[i] = sc.nextInt();
        int p = sc.nextInt(), q = sc.nextInt();
        System.out.println(v[(p - 1)*m + (q - 1)]);
    }
}
全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务