Note de curs, probleme algoritmică, clasa IX/X, 31 octombrie 2014

From Algopedia
Jump to navigationJump to search
#include <cstdio>
#include <iostream>

using namespace std;

struct vector {
	int x, y, z;

	// constructor
	vector (int x = 0, int y = 0, int z = 0) {
		this->x = x;
		this->y = y;
		this->z = z;
	}

	vector operator +(const vector &v) const {
		return vector(
				this->x + v.x,
				this->y + v.y,
				this->z + v.z);
	}

	vector operator -(const vector &v) const {
		return *this + (-v);
	}

	vector operator -() const {
		return vector (-this->x, -this->y, -this->z);
	}

	vector operator *(int a) const {
		return vector (this->x*a,this->y*a,this->z*a);
	}

	friend vector operator *(int a, const vector &v) {
		return v * a;
	}

	friend istream& operator >>(istream &f,vector &v){
		return f>>v.x>>v.y>>v.z;
	}

	friend ostream& operator <<(ostream &f,const vector &v){
		return f<<v.x<<" "<<v.y<<" "<<v.z;
	}
};

int main(void) {
	vector v1;
	vector v2;
	vector v3;
	vector vr;
	//cin>>v1.x>>v1.y>>v1.z;
	cin>>v1>>v2>>v3;
	//scanf ("%d %d %d", &v1.x, &v1.y, &v1.z);
	//scanf ("%d %d %d", &v2.x, &v2.y, &v2.z);
	//scanf ("%d %d %d", &v3.x, &v3.y, &v3.z);

	vr = (3 + 5) * (v1 * 3 + v2 - 7 * v3);

	//printf ("%d %d %d\n", vr.x, vr.y, vr.z);
	cout<<((3 + 5) * (v1 * 3 + v2 - 7 * v3))<<"\n";
	//cout<<(vr<<"\n");
	//(cout<<vr)<<"\n";
	return 0;
}