Wipro - C & C++ Coding Ability

Test Number 3


You are given a positive integer N. Your task is to check whether the number is a perfect square of a number or not. If the number is a perfect square then print 1 else print 0.

INPUT:

First line of input contains T for test cases.

For each test case, the next line contains an integer indicating the value of N.

OUTPUT:
Contains 1 or 0 .



Examples:

Test Case: 1

INPUT:
1

25

OUTPUT:
1



Test Case: 2

INPUT:
1

33

OUTPUT:
0                

#include 

using namespace std;



class Solution {

  public:

    long long int isPerfectSquare(long long int n)

    {

        int ans = sqrt(n);

        if((ans*ans) == n)

        {

            return 1 ;

        }

        else

        return 0 ;

    }

};





int main() {

    int T;

    cin >> T;

    while (T--) {

        long long int n;

        cin >> n;

        Solution ob;

        cout << ob.isPerfectSquare(n) << endl;

    }

    return 0;

}               






You are given an integer value N. Your task is to check whether the number can be written as the sum or the difference of the integer value 10. Print the output in the form of "YES" or "NO". (10+10 , 10-10 , -10-10, -10+10, 10+10+10, 10+10-10 , etc.)

INPUT:
The first line of input contains an integer value T denoting the number of test cases.

For each test case the next line contains a single integer indicating the value of N.

OUTPUT:
Contains the string in the form YES or NO.



Test Case: 1

INPUT:

1

20

OUTPUT:
YES

Explanation:

10+10=20

                   

#include

using namespace std;

int main()

{

    int T;

    cin >> T;

    while(T--)

    {

        int N;

        cin>>N;

        if(N%10==0)

        {

            cout<<"YES"< < endl;

        }

        else

        cout<<"NO"< < endl;

    }

    return 0;

}                   






You are going to buy chocolates for your birthday. The rate of the chocolate costs 5$ each. You pay a total N $ of payment to the shopkeeper with a 0.50$ tip as your birthday celebration. You come to the shop with M $ in your purse. Your task is to calculate the money left in your purse after buying chocolates. 

Condition: You can't buy chocolates rather than of 5$ because you only have 5$ currency notes in your purse. and You can't buy more than the money you have in your purse.



INPUT:
Contains two space separated integers containing the value of N and M respectively.

OUTPUT:
Contains an integer value denoting the amount left in your purse.



Examples:

1. Successful purchasing

Input:
40 140.00

Output:
99.50
99.50 is the amount left in your purse.
2. Purchase any other item.
Input:
59 140.00
OUTPUT:
140.00 
As shopkeeper cancelled the order you have all the money as same as before.
3. Ordered more than the money you have

Input:
440 140.00
OUTPUT:
140.00
Because the shopkeeper cancels the order.                          

#include 

using namespace std;



int main() {

	int X;

	float  Y;

	cin>> X >> Y;

	if(X%5==0 && X<=Y-0.50)

	{

	    cout << fixed << setprecision(2) << Y-(X+0.5) < < endl;

	}

	else 

	cout << fixed << setprecision(2) << Y ;

	

	return 0;

}                          






A tailor sews masks and packs them to sell. Tailor has N masks and needs to decide how many masks to place in each package. Each package must contain the same number of masks. the tailor will choose an integer A between 1 and N, inclusive, and place exactly A masks into each package. the tailor makes as many packages as possible. The tailor then goes to donate some masks to help the poors. The tailor enjoys donating and wants to donate as many as he can. Help the tailor to choose the package size A that will let him donate as many masks as possible.

INPUT:
Input begins with an integer T, the number of test cases.

 Each test case consists of a single integer N, the number of total masks.

OUTPUT:
For each test case, output the package size that will maximize the number of leftover masks. If multiple package sizes will result in the same number of leftover masks, print the largest such size.



Test Case: 1

INPUT:
1

4

OUTPUT:
3

Test Case: 2

INPUT:
1

7

OUTPUT:

4                     

#include 

using namespace std;



int main() 

{

	int T;

	cin >> T;

	while(T--)

	{

	    int N;

        cin >> N;

        int total = (N/2)+1;

        cout << total << endl;

	}

	return 0;

}

                             






You are given two positive integers. Your task is to count all the common divisors of the given two integers.

INPUT:
First Line of input contains T as test cases.

For each test case, the next line contains two space separated integers.

OUTPUT:
Print the count of all the common divisors.



Test Case: 1

1

16 24

OUTPUT:
4

Explanation:

Common divisors of the digits 16 and 24 are 1, 2, 4, 8.

So, the answer is 4.                    

#include 

using namespace std;



class Solution

{

  public:

    long long int commDiv(long long int a,long long int b)

    {



        int count=0;

        for(int i=1 ; i<=b ; i++)

        {

            if(a%i==0 && b%i==0) count++;

            

        }

        return count;

    }

};





int main() {

    int T;

    cin >> T;

    while (T--) {

        long long int a, b;

        cin >> a >> b;

        Solution ob;

        cout< < ob.commDiv(a, b)< < endl;

    }

    return 0;

}