click below for solution

Wednesday, 26 January 2022

Input Format

  • The first line of input contains an integer T, denoting the number of test cases. The description of T test cases follows.
  • The first and only line of each test case contains three space-separated integers X,Y and Z — the number of stocks, the price they were bought at, and the price they can be sold at, respectively.

Output Format

For each test case print on a new line a single integer — Chef's profit after selling all the stocks he has.

Constraints

  • 1T100
  • 1X,Y104
  • YZ104

Sample Input 1 

3
2 5 20
3 1 2
4 5 6

Sample Output 1 

30
3
4

Explanation

Test Case 1: Chef bought X=2 stocks for Y=5 each, making the total amount spent by Chef =25=10.

Chef can sell this stock today for Z=20, making the total amount received by Chef =220=40.

The total profit is then the amount received minus the amount spent, which equals 4010=30.

Test Case 2: Chef bought X=3 stocks for Y=1 each, making the total amount spent by Chef =31=3.

Chef can sell this stock today for Z=2, making the total amount received by Chef =32=6.

The total profit is then the amount received minus the amount spent, which equals 63=3.

Test Case 3: Chef bought X=4 stocks for Y=5 each, making the total amount spent by Chef =45=20.

Chef can sell this stock today for Z=6, making the total amount received by Chef =46=24.

The total profit is then the amount received minus the amount spent, which equals 


Solution

#include <iostream>

using namespace std;

int main()

{

    int t;

    cin>>t;

    while(t--){

        int x,y,z;

        cin>>x>>y>>z;

        int a=x*y;

        int b=x*z;

        cout<<b-a<<endl;

    }

    return 0;

}




 

The Final Task Solution|Bi Wizard School coding Tournament Solution


Your Task:

Your task is to complete the function count_set_bits() which takes an integer array arr as the first argument and the integer n representing the size of the array as the second argument and returns an integer which represents the total count of 1's in the binary representation of each element of the array.


Solution:

int count_set_bits(int *arr, int n) {

    // Write your code here..

    long long c=0;

    for(long long i=0;i<n;i++){

        long long x=arr[i],rem=0,dec=0,j=0;

        while(x>0)

        {

            long long rem=x%2;

            dec=dec*10+rem;

            x/=2;

        }

        while(dec>0){

            long long rem=dec%10;

            if(rem==1){

                c++;

            }

            dec/=10;

        }

        

    }

    return c;

}