Skip to content

Instantly share code, notes, and snippets.

@lazycipher
Created May 7, 2019 14:22
Show Gist options
  • Save lazycipher/6d3809e4291cf1d0452336d720cde386 to your computer and use it in GitHub Desktop.
Save lazycipher/6d3809e4291cf1d0452336d720cde386 to your computer and use it in GitHub Desktop.
HackerRank Problem Box It! In C++
#include<bits/stdc++.h>
using namespace std;
class Box{
private:
int l, b, h;
public:
Box(){
this->l = this->b = this->h = 0;
}
Box(int length, int breadth, int height){
this->l = length;
this->b = breadth;
this->h = height;
}
int getLength() { return this->l; }
int getBreadth() { return this->b; }
int getHeight() { return this->h; }
long long CalculateVolume() {
return (long long)(l)*b*h; }
Box(Box &B){
l = B.l;
b = B.b;
h = B.h;
}
bool operator < (Box &B){
if(l < B.l){
return true;
}else if(b < B.b && l == B.l){
return true;
}else if(h < B.h && b == B.b && h == B.h){
return true;
}
return false;
}
};
ostream &operator<<(ostream &out, Box &B) {
out << B.getLength() << " " << B.getBreadth() << " " << B.getHeight();
return out;
}
void check2()
{
int n;
cin>>n;
Box temp;
for(int i=0;i<n;i++)
{
int type;
cin>>type;
if(type ==1)
{
cout<<temp<<endl;
}
if(type == 2)
{
int l,b,h;
cin>>l>>b>>h;
Box NewBox(l,b,h);
temp=NewBox;
cout<<temp<<endl;
}
if(type==3)
{
int l,b,h;
cin>>l>>b>>h;
Box NewBox(l,b,h);
if(NewBox<temp)
{
cout<<"Lesser\n";
}
else
{
cout<<"Greater\n";
}
}
if(type==4)
{
cout<<temp.CalculateVolume()<<endl;
}
if(type==5)
{
Box NewBox(temp);
cout<<NewBox<<endl;
}
}
}
int main()
{
check2();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment