九度OJ 1001 A+B for Matrices
2013-05-15 19:32
344 查看
题目链接:http://ac.jobdu.com/problem.php?pid=1001
题目分析:
题目看起来要耐心,题目写的很难懂,看懂了之后会发现原来是一道非常简单的题目。
首先输入矩阵的行列数,然后输入矩阵的信息,这里要输入两个一样行列数的矩阵,然后将两个矩阵相加,分别计算相加之后的得到的新矩阵的每一行,每一列都为0的个数,然后得到为0个数的总和。
源代码:
题目分析:
题目看起来要耐心,题目写的很难懂,看懂了之后会发现原来是一道非常简单的题目。
首先输入矩阵的行列数,然后输入矩阵的信息,这里要输入两个一样行列数的矩阵,然后将两个矩阵相加,分别计算相加之后的得到的新矩阵的每一行,每一列都为0的个数,然后得到为0个数的总和。
源代码:
#include<iostream> using namespace std; int main() { int i,j; //行列数 int k = 0; //行,列和为0的个数 int sum1 = 0, sum2 = 0; //行的和,列的和 int a1[100][100] = {0}, a2[100][100] = {0};//二维数组保存矩阵信息 while(1) { cin>>i; if (i == 0) { break; //输入0时程序结束 } cin>>j; //输入第一个矩阵 for(int n1 = 0; n1 < i; n1++) { for(int n2 = 0; n2 < j; n2++) { cin>>a1[n1][n2]; } } //输入第二个矩阵 for(int n1 = 0; n1 < i; n1++) { for(int n2 = 0; n2 < j; n2++) { cin>>a2[n1][n2]; } } //计算每一行相加后为0的个数 for(int n1 = 0; n1 < i; n1++) { for (int n2 = 0; n2 < j; n2++) { sum1 = sum1 + a1[n1][n2] + a2[n1][n2]; } if (sum1 == 0) { k++; } sum1 = 0; } //计算每一列相加后为0的个数 for(int n2 = 0; n2 < j; n2 ++) { for (int n1 = 0; n1 < i; n1 ++) { sum2 = sum2 + a1[n1][n2] + a2[n1][n2]; } if (sum2 == 0) { k++; } sum2 = 0; } cout<<k<<endl; k = 0; } return 0; }
相关文章推荐
- 九度OJ 1001 A+B for Matrices
- 九度OJ 1001 A+B for Matrices
- 九度oj 题目1001:A+B for Matrices 【ZJU2011考研机试题1】
- 九度OJ—题目1001:A+B for Matrices
- 九度OJ 题目1001:A+B for Matrices
- 1001 A+B for Matrices 九度Online Judge
- 题目1001:A+B for Matrices
- A+B for Matrices_1001
- 1001 A+B for Matrices
- 九度1001 A+B for Matrices
- 九度 题目1001:A+B for Matrices
- 【九度OJ】题目1001:A+B for Matrices
- 题目1001:A+B for Matrices
- 九度oj-1001-A+B for Matrices
- 题目1001:A+B for Matrices
- 九度 题目1001:A+B for Matrices
- 九度题目1001:A+B for Matrices
- 九度OJ-1001:A+B for Matrices
- 题目1001:A+B for Matrices
- 题目1001:A+B for Matrices