首页 技术 正文
技术 2022年11月16日
0 收藏 608 点赞 4,697 浏览 2322 个字

2953: A代码填充–学画画

时间限制: 1 Sec  内存限制: 128 MB

提交: 62  解决: 52

题目描述

最近小平迷上了画画,经过琨姐的指导,他学会了RGB色彩的混合方法。对于两种颜料1和颜料2,其对应的RGB色彩表示分别为(R1,G1,B1)和(R2,G2,B2)。

将m份颜料1和n份颜料2进行混合,混合后色彩的RGB表示为 ((m*R1+n*R2)/(m+n),(m*G1+n*G2)/(m+n),(m*B1+n*B2)/(m+n))。

注:本题只需要提交填写部分的代码,请按照C++方式提交。

#include <iostream>

using namespace std;

class RGB

{

public:

    RGB(int r=0,int g=0,int b=0);

    friend RGB operator+(RGB &,RGB &);

    friend RGB operator*(int ,RGB &);

    friend RGB operator/(RGB &,int);

    friend ostream& operator<<(ostream&,RGB&);

    friend istream& operator>>(istream&,RGB&);

    RGB RGBmix(RGB &rgb1,RGB &rgb2,int m,int n);

private:

    int red,green,blue;

};

RGB::RGB(int r,int g,int b)

{

    red=r;

    green=g;

    blue =b;

}

istream& operator>>(istream &in,RGB &rgb)

{

    in>>rgb.red>>rgb.green>>rgb.blue;

    return in;

}

ostream& operator<<(ostream &out,RGB &rgb)

{

    out<<rgb.red<<","<<rgb.green<<","<<rgb.blue<<endl;

    return out;

}

RGB operator*(int n,RGB &rgb)

{

    return RGB(n*rgb.red,n*rgb.green,n*rgb.blue);

}

/*

    请在该部分补充缺少的代码

*/

RGB RGB::RGBmix(RGB &rgb1,RGB &rgb2,int m,int n)

{

    RGB t,t1,t2;

    t=(t1=m*rgb1)+(t2=n*rgb2);

    return t/(m+n);

}

int main()

{

    RGB rgb1,rgb2,rgb;

    int m,n;

    cin>>rgb1>>rgb2;

    cin>>m>>n;

    rgb =rgb.RGBmix(rgb1,rgb2,m,n);

    cout<<rgb<<endl;

    return 0;

}

输入

颜料1和颜料2的 R,G,B 成分(均为整数)

颜料1和颜料2的份数(均为整数)

输出

混合颜料的 R,G,B 成分(均为整数,不进行四舍五入)

样例输入

0 0 0 255 255 255
1 1

样例输出

127,127,127

你  离  开  了  ,  我  的  世  界  里  只  剩  下  雨  。  。  。

#include <iostream>
using namespace std;
class RGB
{
public:
RGB(int r=0,int g=0,int b=0);
friend RGB operator+(RGB &,RGB &);
friend RGB operator*(int ,RGB &);
friend RGB operator/(RGB &,int);
friend ostream& operator<<(ostream&,RGB&);
friend istream& operator>>(istream&,RGB&);
RGB RGBmix(RGB &rgb1,RGB &rgb2,int m,int n);
private:
int red,green,blue;
};
RGB::RGB(int r,int g,int b)
{
red=r;
green=g;
blue =b;
}
istream& operator>>(istream &in,RGB &rgb)
{
in>>rgb.red>>rgb.green>>rgb.blue;
return in;
}
ostream& operator<<(ostream &out,RGB &rgb)
{
out<<rgb.red<<","<<rgb.green<<","<<rgb.blue<<endl;
return out;
}
RGB operator*(int n,RGB &rgb)
{
return RGB(n*rgb.red,n*rgb.green,n*rgb.blue);
}
RGB operator+(RGB &a,RGB &b)
{
RGB c;
c.blue=a.blue+b.blue;
c.green=a.green+b.green;
c.red=a.red+b.red;
return c;
}
RGB operator/(RGB &a,int b)
{
RGB c;
c.blue=a.blue/b;
c.green=a.green/b;
c.red=a.red/b;
return c;
}
RGB RGB::RGBmix(RGB &rgb1,RGB &rgb2,int m,int n)
{
RGB t,t1,t2;
t=(t1=m*rgb1)+(t2=n*rgb2);
return t/(m+n);
}
int main()
{
RGB rgb1,rgb2,rgb;
int m,n;
cin>>rgb1>>rgb2;
cin>>m>>n;
rgb =rgb.RGBmix(rgb1,rgb2,m,n);
cout<<rgb<<endl;
return 0;
}

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,031
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,860