Skip to content

Commit

Permalink
Merge pull request #58 from rajashree23/bon
Browse files Browse the repository at this point in the history
Added code for Bon Appetit
  • Loading branch information
Srikant Singh committed Oct 9, 2018
2 parents f448725 + 2e3461b commit f63268b
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Hackerrank/Bon Appetit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <bits/stdc++.h>
#include<cmath>
using namespace std;

void bonAppetit()
{
int n,k,bill[100000],b,i,s=0;
cin>>n>>k;
for(i=0;i<n;i++)
cin>>bill[i];
cin>>b;
for(i=0;i<n;i++)
{
if(i!=k)
s=s+bill[i];
}
s=s/2;
if(s==b)
{
cout<<"Bon Appetit";

}
else
{
cout<<abs(b-s);
}

}
int main()
{
bonAppetit();
return 0;
}

36 changes: 36 additions & 0 deletions Hackerrank/Kangaroo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include<iostream>
using namespace std;
int main()
{
int x1,x2,v1,v2,t1=0,c=0;
cin>>x1>>v1>>x2>>v2;
if((x1>x2 && v1>v2) || (x2>x1 && v2>v1) )
cout<<"NO";
else
{
while(x1!=x2)
{ c++;
if(c==10000)
{
break;
}
x1+=v1;

x2+=v2;
if(x1==x2)
{
t1=1;
break;
}

}
if(t1==1)

cout<<"YES";
else
cout<<"NO";


}
return 0;
}

0 comments on commit f63268b

Please sign in to comment.