YTU 2640: 编程题:运算符重载---矩阵求和
2640: 编程题:运算符重载---矩阵求和
时间限制: 1 Sec 内存限制: 128 MB
提交: 484 解决: 190
题目描述
输入
两个2行3列矩阵
输出
矩阵之和
样例输入
1 2 3
4 5 6 7 8 9
0 1 2
样例输出
8 10 12
4 6 8
提示
只提交begin到end部分的代码
迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……
#include <iostream>
using namespace std;
class Matrix
{
public:
Matrix();
friend Matrix operator+(Matrix &,Matrix &);
friend ostream& operator<<(ostream&,Matrix&);
friend istream& operator>>(istream&,Matrix&);
private:
int mat[2][3];
};
Matrix::Matrix()
{
int i,j;
for(i=0; i<2; i++)
for(j=0; j<3; j++)
mat[i][j]=0;
}
istream & operator>>(istream & input,Matrix & m)
{
int i,j;
for(i=0; i<2; i++)
for(j=0; j<3; j++)
input>>m.mat[i][j];
return input;
}
Matrix operator+(Matrix &m1,Matrix &m2)
{
Matrix m;
for(int i=0; i<2; ++i)
for(int j=0; j<3; ++j)
{
m.mat[i][j]=m1.mat[i][j]+m2.mat[i][j];
}
return m;
}
ostream& operator <<(ostream &output,Matrix &m)
{
int i,j;
for(i=0; i<2; ++i)
{
for( j=0; j<3; ++j)
{
output<<m.mat[i][j]<<" ";
}
output<<endl;
}
return output;
}
int main()
{
Matrix a,b,c;
cin>>a;
cin>>b;
c=a+b;
cout<<c<<endl;
return 0;
}
#include <iostream>
using namespace std;
class Matrix
{
public:
Matrix();
friend Matrix operator+(Matrix &,Matrix &);
friend ostream& operator<<(ostream&,Matrix&);
friend istream& operator>>(istream&,Matrix&);
private:
int mat[2][3];
};
Matrix::Matrix()
{
int i,j;
for(i=0; i<2; i++)
for(j=0; j<3; j++)
mat[i][j]=0;
}
istream & operator>>(istream & input,Matrix & m)
{
int i,j;
for(i=0; i<2; i++)
for(j=0; j<3; j++)
input>>m.mat[i][j];
return input;
}
Matrix operator+(Matrix &m1,Matrix &m2)
{
Matrix m;
for(int i=0; i<2; ++i)
for(int j=0; j<3; ++j)
{
m.mat[i][j]=m1.mat[i][j]+m2.mat[i][j];
}
return m;
}
ostream& operator <<(ostream &output,Matrix &m)
{
int i,j;
for(i=0; i<2; ++i)
{
for( j=0; j<3; ++j)
{
output<<m.mat[i][j]<<" ";
}
output<<endl;
}
return output;
}
int main()
{
Matrix a,b,c;
cin>>a;
cin>>b;
c=a+b;
cout<<c<<endl;
return 0;
}
YTU 2640: 编程题:运算符重载---矩阵求和的更多相关文章
- POJ C++程序设计 编程题#3 编程作业—运算符重载
编程题 #3 来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB 描述 写一个二维数组 ...
- POJ C++程序设计 编程题#1 编程作业—运算符重载
编程题 #2 来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB 描述 下面的MyIn ...
- YTU 2598: 编程题B-小平智斗自动售货机
2598: 编程题B-小平智斗自动售货机 时间限制: 1 Sec 内存限制: 128 MB 提交: 268 解决: 69 题目描述 LYH自动售货机在销售商品时,具有自动找钱功能.但是找零的最小单 ...
- YTU 2597: 编程题B-选拔飞行员
2597: 编程题B-选拔飞行员 时间限制: 1 Sec 内存限制: 128 MB 提交: 131 解决: 35 题目描述 2100年空军选拔高中生飞行学员基本条件要求如下,年龄范围:16-19周 ...
- YTU 2596: 编程题B-日期格式
2596: 编程题B-日期格式 时间限制: 1 Sec 内存限制: 128 MB 提交: 981 解决: 74 题目描述 注:本题只需要提交编写的函数部分的代码即可. 将输入的日期格式 月/日/年 ...
- YTU 2858: 编程题AB-骨牌铺方格
2858: 编程题AB-骨牌铺方格 时间限制: 1 Sec 内存限制: 128 MB 提交: 87 解决: 23 题目描述 在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出 ...
- YTU 2845: 编程题AB-卡片游戏
2845: 编程题AB-卡片游戏 时间限制: 1 Sec 内存限制: 128 MB 提交: 30 解决: 13 题目描述 小明对数字的序列产生了兴趣: 现有许多张不同的数字卡片,用这若干张卡片能排 ...
- YTU 2837: 编程题B-狐狸算卦
2837: 编程题B-狐狸算卦 时间限制: 1 Sec 内存限制: 128 MB 提交: 76 解决: 52 题目描述 注:本题只需要提交需要完善部分的代码,请按照C++方式提交. 小熊和狐狸是邻 ...
- YTU 2535: C++复数运算符重载(+与<<)
2535: C++复数运算符重载(+与<<) 时间限制: 1 Sec 内存限制: 128 MB 提交: 867 解决: 532 题目描述 定义一个复数类Complex,重载运算符&qu ...
随机推荐
- AC手动机 [原创]
题目背景 Monster_Qi 又双叒叕拿到了rank1! 在开心之余他决定帮助蒟蒻floatiy拿到合适的排名. 题目描述 已知考试有n道题,每道题有num个测试点,有m个人 b[x,i,j](01 ...
- idea导入本地idea的web项目(服务器用的是tomcat)
开始吧!!! 点击import project. 我以SpringMVCPro3为例,选中,点击OK 点击next 继续next 随便吧,我点击yes 选中工程,点击next lib1不要钩,然后点击 ...
- php7 安装swoole扩展
昨天无意中看到一篇关于直播的视频教程 里面讲到了swoole,对于这个东西我相信大家(接近1年phper)都是听过它,但没有真正去用它,当然也是不知道如何使用(me too). 此处总结一下(借鉴了几 ...
- C++ string 转整数
使用 sstream 完成转换, #include <iostream> #include <string> #include <sstream> #include ...
- Jmeter关联,正则表达式提取器使用1
Jmeter关联,正则表达式提取器使用 一.Jmeter关联的方式: Jmeter中关联可以在需要获取数据的请求上 右键-->后置处理器 选择需要的关联方式,如下图有很多种方法可以提取动态 ...
- 牛客网sql练习
一建表语句 /* Navicat MySQL Data Transfer Source Server : test Source Server Version : 50717 Source Host ...
- xtu summer individual 5 D - Subsequence
Subsequence Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID ...
- 苹果装WIN 7
一.准备:1.8G或以上的正版U盘或者移动硬盘,提前备份U盘数据(2013款air要求安装64位系统,市面上比较多U盘不是正版盘,一般做不成功,要换盘) 2.64位纯净版Windows7 ISO的下载 ...
- python 时间四舍五入
假设时间格式为 YYYYMMDDhhmm , 比如201508010001 代表2015年8月1日0点01分. 现在有需求,要求一个start 和一个 end 变量的字符串 都是这种格式的时间. 需要 ...
- eclipse常用使用指南
1.eclipse添加new/删除/一个tomcat. 步骤:window->preference->server->runtime environment.remove掉,再重新n ...