成人无码视频,亚洲精品久久久久av无码,午夜精品久久久久久毛片,亚洲 中文字幕 日韩 无码

資訊專(zhuān)欄INFORMATION COLUMN

[HackerRank] Diagonal Difference

warmcheng / 2313人閱讀

Problem

Given a square matrix of size N x N, calculate the absolute difference between the sums of its diagonals.

Input Format

The first line contains a single integer, N. The next N lines denote the matrix"s rows, with each line containing N space-separated integers describing the columns.

Output Format

Print the absolute difference between the two sums of the matrix"s diagonals as a single integer.

Sample Input

3

11    2     4
4     5     6
10    8     -12

Sample Output

15

Explanation

The primary diagonal is:

11
      5
            -12

Sum across the primary diagonal: 11 + 5 - 12 = 4

The secondary diagonal is:

            4
      5
10

Sum across the secondary diagonal: 4 + 5 + 10 = 19
Difference: |4 - 19| = 15

Solution

import java.io.*;
import java.util.*;
public class Solution {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int pSum = 0, sSum = 0;
        int a[][] = new int[n][n];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                a[i][j] = in.nextInt();
            }
        }
        for(int i=0; i           
               
                                           
                       
                 

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://m.hztianpu.com/yun/66019.html

相關(guān)文章

  • Hackerrank Practice

    摘要:數(shù)組中重復(fù)元素的個(gè)數(shù)題目找到一個(gè)數(shù)組中重復(fù)元素的個(gè)數(shù)。能否成為題目互減,直到的時(shí)候。此方法精彩此方法更精彩找兩邊相等的 Anagram 拆分?jǐn)?shù)組 看一半操作幾次能成為另一半的anagram 題目 輸入第一行是要判斷的字符串的個(gè)數(shù)n,之后的n行輸入為需要判斷的字符串。每個(gè)字符串str,是兩個(gè)等長(zhǎng)字符串的合體,所以長(zhǎng)度一定是偶數(shù)。若為奇數(shù),返回-1。所以str分成兩個(gè)substring,右...

    arashicage 評(píng)論0 收藏0
  • [HackerRank] Simple Array Sum | A Very Big Sum

    Simple Array Sum Problem Given an array of N integers, can you find the sum of its elements? Input Format The first line contains an integer, N, denoting the size of the array. The second line contain...

    harriszh 評(píng)論0 收藏0
  • [HackerRank] Plus Minus

    Problem Given an array of integers, calculate which fraction of its elements are positive, which fraction of its elements are negative, and which fraction of its elements are zeroes, respectively. Pri...

    leeon 評(píng)論0 收藏0
  • [HackerRank] Staircase

    Problem Your teacher has given you the task of drawing a staircase structure. Being an expert programmer, you decided to make a program to draw it for you instead. Given the required height, can you p...

    explorer_ddf 評(píng)論0 收藏0
  • [HackerRank] Time Conversion

    Problem Given a time in AM/PM format, convert it to military (24-hour) time. Input Format A single string containing a time in 12-hour clock format. Output Format Convert and print the given time in 2...

    longmon 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

閱讀需要支付1元查看
<