当前位置:网站首页>PTA 7-2 Summation and Counting of Diagonal Elements of Square Matrices Solution
PTA 7-2 Summation and Counting of Diagonal Elements of Square Matrices Solution
2022-08-10 10:03:00 【An Ran_】
For an input square matrix of
N*N, find the sum of the elements on the two diagonals and the number of non-zero elements.input format:
Enter a positive integer
Nnot exceeding 20 in the first line,
In the nextNlines, enter theNof each line of the square matrix in turn.code>N elements, the elements of the square matrix are integers whose absolute value does not exceed 1000, separated by spaces.Output format:
Output the sum of the elements on the two diagonals of the square matrix and the number of non-zero elements in the format
sum =in one line, where, count =. andrepresent the sum ofelementsandnumber of non-zero elementsrespectively, and are replaced with the actual number when outputting.
Tips: (1) The intersecting elements of the two diagonals are not repeatedly calculated; (2) The output is strictly in the specified format, and characters such as spaces and line breaks are not allowed to be added or deleted at will.Input Sample 1:
41 2 3 41 2 3 40 1 2 30 1 2 3Example output 1:
sum = 16, count = 7.Input Sample 2:
51 2 3 2 11 2 3 2 11 2 3 2 11 2 3 2 11 2 3 2 1Example output:
sum = 15, count = 9.
topic analysis
1. The title requires to calculate the sum of the main diagonal elements, and requires no repetition; requires to calculate the number of non-zero elements (on the diagonal)
2. Diagonal element coordinate feature - Main diagonal element-i=j——Subdiagonal element feature-i=n-1-j
3. Special requirements: Do not add or delete characters such as spaces, newlines, etc. at will; Diagonal cross-repetitive elements cannot be counted repeatedly
#include #define N 21int main(){int a[N][N];int n,i,j;int sum=0,count=0;scanf("%d",&n);for(i=0;i 边栏推荐
猜你喜欢

The web project accesses static resources inside the reference jar

腾讯发布四足机器人 Max 二代版本,梅花桩上完成跳跃、空翻

shell iterates over folders and outputs

裸辞→自我放松→闭关→复习→斩获Offer

【数据仓库】什么是 Azure Synapse,它与 Azure Data Bricks 有何不同?

IDEA中xml文件头报错:URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs)

「数据架构」数据模型,数据字典,数据库模式 和ERD的比较

【API Management】What is API Management and why is it important?

07 【动态组件 组件注册】

大连理工&鹏城&UAE提出用于伪装目标检测的混合尺度三重网络ZoomNet,性能SOTA!
随机推荐
《广州市公路工程安全生产监督管理办法》印发,从六大方面进行修订
MySQL 执行查询流程
09 【Attributes继承 provide与inject】
用.bat文件做Airtest脚本的多设备批量运行
shell iterates over folders and outputs
ZZULIOJ 1116 删除元素【删】
Chapter 3 Search and Graph Theory (3)
2022-08-09 第六小组 瞒春 学习笔记
Array of shell scripts
ESP8266 教程1 — ESP8266硬件平台介绍
06 【生命周期 模板引用】
The Generation of Matlab Symbolic Functions and the Calculation of Its Function Values
【Software Exam System Architect】System Reliability Analysis and Design ① System Reliability Analysis
Development environment variable record under win
「业务架构」TOGAF建模:组织分解图(组织映射)
【知识论概念】《理由论的进展》鲁汶大学2022最新220页博士论文
【软考 系统架构设计师】案例分析⑥ Web应用系统架构设计
「应用架构」TOGAF建模:应用程序迁移图
在兄弟连战狼班参加PHP培训做行业领先人才
对话陈赐靓:哪吒要让高端产品大众化