题目1001:A+B for Matrices
2013-07-05 08:41
288 查看
只要读懂是什么意思就好做了。。。
这个题的意思是:两个矩阵A,B,相加后得到矩阵C,求C中行或列全为0的总和。。。
是不是很水。。。
#include<stdio.h>
int main()
{
int i,j,count,flag,m,n;
int a[100][100],b[100][100],c[100][100];
while(scanf("%d",&m)!=EOF && m!=0){
scanf("%d",&n);
for(i=0;i<m;i++){
for(j=0;j<n;j++) scanf("%d",&a[i][j]);
}
for(i=0;i<m;i++){
for(j=0;j<n;j++){
scanf("%d",&b[i][j]);
c[i][j]=a[i][j]+b[i][j];
}
}
count=0;
for(i=0;i<m;i++){
flag=0;
for(j=0;j<n;j++){
if(c[i][j]!=0){ flag=1; break;}
}
if(flag==0) count++;
}
for(i=0;i<n;i++){
flag=0;
for(j=0;j<m;j++){
if(c[j][i]!=0){ flag=1; break;}
}
if(flag==0) count++;
}
printf("%d\n",count);
}
return 0;
}
这个题的意思是:两个矩阵A,B,相加后得到矩阵C,求C中行或列全为0的总和。。。
是不是很水。。。
#include<stdio.h>
int main()
{
int i,j,count,flag,m,n;
int a[100][100],b[100][100],c[100][100];
while(scanf("%d",&m)!=EOF && m!=0){
scanf("%d",&n);
for(i=0;i<m;i++){
for(j=0;j<n;j++) scanf("%d",&a[i][j]);
}
for(i=0;i<m;i++){
for(j=0;j<n;j++){
scanf("%d",&b[i][j]);
c[i][j]=a[i][j]+b[i][j];
}
}
count=0;
for(i=0;i<m;i++){
flag=0;
for(j=0;j<n;j++){
if(c[i][j]!=0){ flag=1; break;}
}
if(flag==0) count++;
}
for(i=0;i<n;i++){
flag=0;
for(j=0;j<m;j++){
if(c[j][i]!=0){ flag=1; break;}
}
if(flag==0) count++;
}
printf("%d\n",count);
}
return 0;
}
相关文章推荐
- 题目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
- 【C语言】题目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
- 九度题目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 【ZJU2011考研机试题1】
- 九度OJ题目1001:A+B for Matrices
- 题目1001:A+B for Matrices
- 题目 1001 A+B for Matrices 九度Online Judge
- 题目1001:A+B for Matrices