Last Updated: 25 Nov, 2020

Total Salary

Easy

Problem statement

Ninja just got an offer letter from a reputable company. The company sent him an offer letter along with the salary bifurcation.

In that bifurcation,Total Salary was not mentioned but instead a ‘basicSalary’ and an upper case character representing grade was mentioned, depending on which the Total Salary is calculated.

Help Ninja in calculating his total salary, where total salary is defined as:

‘totalSalary’ = ‘basic’ + ‘hra’ + ‘da’ + ‘allowance’ - ‘pf’

The above terms are as follows:

‘hra’ = 20% of ‘basic’
‘da’ = 50% of ‘basic’
‘allowance’ = 1700 if grade = ‘A’
‘allowance’ = 1500 if grade = ‘B’
‘allowance’ = 1300 if grade = ‘C' or any other character
‘pf’ = 11% of ‘basic’.

Note :

Round off the ‘totalSalary’ and then print the integral part only.

'x.5' type values will always be round up, for example, 1.5, 2.5 will be round off to 2, 3 respectively.
Input format :
The first line of input contains an integer ‘T’ denoting the number of test cases. Then each test case follows:

The first and the only line of each test contains an integer denoting ‘basicSalary’ and an Uppercase character representing Grade (separated by space).
Output Format :
The output will contain a single integer representing Total Salary.

The output of each test case will be printed on a separate line.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints :
0 <= 'basicSalary' <= 7 * (10 ^ 5)

Time Limit: 1 sec.

Approaches

01 Approach

Use simple math operations.

 

Algorithm:

 

  • First calculate take variables ‘hra’, ‘da’, ‘pf’ of double data type and ‘allowance’ of integer data type
  • Calculate the values of ‘hra’, ‘da’, ‘pf’ by the given formulas and store them in the respective variables
  • Now, store the ‘allowance’ according to the given uppercase alphabets in the inputs by applying if conditions
  • Now calculate Total salary by summing up all the variables ‘hra’, ‘da’, pf’, ‘allowance’ and store them in a variable say ‘totalSalary’.
  • Now make the round value of ‘totalSalary’ and store the value in the variable say ‘ans’.
  • Return ‘ans’.