用一维数组保存二维矩阵

矩阵元素定位

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.把简历改哈 2.猛投,狠投 3.把基础打牢 这样你在有机会的时候,才能抓住
点赞 评论 收藏
分享
人力小鱼姐:实习经历没有什么含金量,咖啡店员迎宾这种就别写了,其他两段包装一下 想找人力相关的话,总结一下个人优势,结合校园经历里有相关性的部分,加一段自我评价
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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