九度OJ
来源:互联网 发布:java引入js跨域 编辑:程序博客网 时间:2024/06/05 11:02
这个题的意思是:两个矩阵A,B,相加后得到矩阵C,求C中行或列全为0的总和。。
- 样例输入:
2 21 11 1-1 -110 92 31 2 34 5 6-1 -2 -3-4 -5 -60
- 样例输出:
15
#include<iostream>
#include<cstdio>
using namespace std;
int Rows(int matrics[10][10],int a,int b){
int rows=0;
for(int i=0;i<a;i++){
int temp=1;
for(int j=0;j<b;j++){
if(matrics[i][j]!=0){
temp=0;
break;
}
}
rows+=temp;
}
return rows;
}
int Cols(int matrics[10][10],int a,int b){对于一维数组来说,数组作为函数参数传递,相当于传址,而不是传值,会改变数组元素的值
int cols=0;
for(int i=0;i<b;i++){
int temp=1;
for(int j=0;j<a;j++){
if(matrics[j][i]!=0){
temp=0;
break;
}
}
cols+=temp;
}
return cols;
}
void mutiply(int matrics1[10][10],int matrics2[10][10],int a,int b){高维数组第一个 可以不写大小,其他的必须写[][10]
int i=0,j=0;
for(i=0;i<a;i++){
for(j=0;j<b;j++){
matrics1[i][j]=matrics1[i][j]+matrics2[i][j];
}
}
}
int main(){
int row=0,col=0;
while(scanf("%d",&row)!=EOF,row!=0){ //while(scanf("%d",&row)!=0){这样写报错 ERROR: Output Limit Exceed
也可以写成 whilescanf("%d",&row)!=EOF,row)
int matrics1[10][10],matrics2[10][10];
cin>>col;
int i=0,j=0;
for(i=0;i<row;i++){
for(j=0;j<col;j++){
cin>>matrics1[i][j];
}
}
for(i=0;i<row;i++){
for(j=0;j<col;j++){
cin>>matrics2[i][j];
}
}
mutiply(matrics1,matrics2,row,col);
int aa=Rows(matrics1,row,col)+Cols(matrics1,row,col);
cout<<aa<<endl;
}
return 0;忘记了写return
}
阅读全文
0 0
- 【九度OJ】:九度OJ 1050
- 【九度OJ】:九度OJ 1053
- 【九度OJ】:九度OJ 1056
- 【九度OJ】:九度OJ 1059
- 【九度OJ】:九度OJ 1206
- 九度OJ:1000
- 【九度OJ】 1006
- 九度 OJ 1499
- 九度OJ-1002
- 九度OJ-1003
- 九度OJ 1004
- 九度OJ 1003
- 九度oj 采药
- 九度OJ 1001
- 九度OJ 1015
- 九度oj 1972
- 九度OJ 1161
- 九度OJ 1016
- 6410 移植busybox+X+matchbox+gtk笔记
- js常用的自带的函数属性
- SQLServer 按日,周,月,季,年统计
- Django-xadmin的使用
- 51 Nod 1441 质因子筛
- 九度OJ
- Linux parted磁盘分区
- 立方星CubeSat
- 如何解决滑动冲突
- python range的最简单用法
- ffmpeg的新东东:AVFilter
- CodeForces 550 D.Regular Bridge(构造)
- lua 修改字体属性
- javaEE的十三个技术规范