Problem Description
source:https://uva.onlinejudge.org/external/123/12342.html
People of a certain country have a little interest in paying tax. This is not the case that they do not love the country or they do not want to obey the law, but the problem is the complex calculations for payable tax. Most of the people do not understand the rule and some lawyers take high charges to help(?) them. So, most of the people just avoid paying tax. Realizing this, the Government decided to automate the taxpaying system and appointed you to program a tax calculator that takes a persons yearly income as input and calculate the payable tax for him. Here is the rule for calculate payable tax for an individual:
1. The first 180,000/- of income is tax free.
2. Next 300,000/- will have 10% tax.
3. Next 400,000/- will have 15% tax.
4. Next 300,000/- will have 20% tax.
5. The rest will have 25% tax.
6. The minimum payable tax will be 2,000/-. That is if anyones tax is below 2,000/- (but of course greater than zero) he must pay 2,000/-
7. The payable tax must be an integer. If the calculated tax is a floating point then it must be replaced by the smallest integer greater than the payable tax.
Input
The first line of input will contain an integer T (T ≤ 5000) which denotes the number of test cases. Each of the following T lines contains an integer k (1 ≤ k ≤ 109 ).
Output
For each line of input output the case number and an integer which is the payable tax for the given income. Illustration of 3rd sample:
Sample Input
3
180001
12345
615000
Sample Output
Case 1: 2000
Case 2: 0
Case 3: 50250
Solution:
source:https://uva.onlinejudge.org/external/123/12342.html
People of a certain country have a little interest in paying tax. This is not the case that they do not love the country or they do not want to obey the law, but the problem is the complex calculations for payable tax. Most of the people do not understand the rule and some lawyers take high charges to help(?) them. So, most of the people just avoid paying tax. Realizing this, the Government decided to automate the taxpaying system and appointed you to program a tax calculator that takes a persons yearly income as input and calculate the payable tax for him. Here is the rule for calculate payable tax for an individual:
1. The first 180,000/- of income is tax free.
2. Next 300,000/- will have 10% tax.
3. Next 400,000/- will have 15% tax.
4. Next 300,000/- will have 20% tax.
5. The rest will have 25% tax.
6. The minimum payable tax will be 2,000/-. That is if anyones tax is below 2,000/- (but of course greater than zero) he must pay 2,000/-
7. The payable tax must be an integer. If the calculated tax is a floating point then it must be replaced by the smallest integer greater than the payable tax.
Input
The first line of input will contain an integer T (T ≤ 5000) which denotes the number of test cases. Each of the following T lines contains an integer k (1 ≤ k ≤ 109 ).
Output
For each line of input output the case number and an integer which is the payable tax for the given income. Illustration of 3rd sample:
Sample Input
3
180001
12345
615000
Sample Output
Case 1: 2000
Case 2: 0
Case 3: 50250
Solution:
#include <algorithm> #include <cstdio> #include <cmath> #include <string> #include <vector> #include<stdio.h> #include<stdlib.h> using namespace std; int main() { long int t,income,i,total; long double tax; while(scanf("%ld",&t)==1) { for(i=1;i<=t;i++) { scanf("%ld",&income); tax=0; if(income>180000) { income-=180000; if(income>=300000) { tax=(300000*10.0)/100.0; income-=300000; if(income>=400000) { tax+=(400000*15.0)/100.0; income-=400000; if(income>=300000) { tax+=(300000*20.0)/100.0; income-=300000; tax+=(income*25.0)/100.0; } else { tax+=(income*20.0)/100.0; } } else { tax+=(income*15.0)/100.0; } } else { tax=(income*10.0)/ 100.0; if(tax<2000) tax=2000; } } total=(long int)tax; if(abs(total-tax)>0.0) total+=1; printf("Case %ld: %ld\n",i,total); } } }
No comments:
Post a Comment
Write your comment - Share Knowledge and Experience