Posts

Showing posts from November, 2020

Hackerrank's Problem Solving solutions( Bill Division, Sales by Match, Drawing Book ) :

Problem 19: Bill Division Solution: (in c++) ( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder) #include< bits/stdc++.h > using namespace std ; int main () { long long n , k , i , b , sum = 0 , unfair , fair , refund ; cin >> n >> k ; long long bill [ n ]; for ( i = 0 ; i < n ; i ++) { cin >> bill [ i ]; sum = sum + bill [ i ]; } cin >> b ; unfair = sum / 2 ; fair =( sum - bill [ k ])/ 2 ; refund = unfair - fair ; if ( b == fair ) { cout << "Bon Appetit" ; } else { cout << refund ; } }   This code is simple. There's no need for any explanation.         Problem 20: Sales by Match Solution: (in c++) ( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder) #include< bits/stdc++.h > using namespace st

Hackerrank's Problem Solving solutions( Divisible Sum Pairs, Migratory Birds, Day of the Programmer ) :

Problem 16: Divisible Sum Pairs Solution: (in c++) ( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder) #include< bits/stdc++.h > using namespace std ; int main () { int n , k ; cin >> n >> k ; int a [ n ]; for ( int p = 0 ; p < n ; p ++) { cin >> a [ p ]; } int count = 0 ; for ( int i = 0 ; i < n ; i ++)      { for ( int j = i + 1 ; j < n ; j ++)          { if (( a [ i ]+ a [ j ])% k == 0 )              { count ++; } } } cout << count ; } This code is simple. There's no need for any explanation.         Problem 17: Migratory Birds Solution: (in c++) ( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder) #include< bits/stdc++.h > using namespace