G(UVALive 7815)

来源:互联网 发布:在ipad上开淘宝店 编辑:程序博客网 时间:2024/06/06 17:24

点击此处将进入题目

                                G

The amount of income tax imposed on any taxpayer depends on his/her income.
For an income less than or equal to 1,000,000 Oshloobs, no tax is paid.
For an income greater than 1,000,000 and less than or equal to 5,000,000 Oshloobs,
the tax is 10% of the income. For an income over 5,000,000 Oshloobs, the tax is 20% of the income.
You should write a program to calculate the net income of any given employee after the deducted tax.
 
Input 
There are multiple lines in the input. Each line contains
an employee’s income before the tax, which is a positive integer,
a multiple of 1000, and not greater than 10,000,000.
The input terminates with a line containing ‘0’ which should not be processed.
 
Output
For each employee, output a line containing the net income after the deducted tax.
 
Sample Input
10000
50000
2000000
7500000
0
 
Sample Output
10000
50000
1800000
6000000


这道题很简单,就是如果超过1000000就打九折,超过5000000就打八折。

但是要注意的是精确度,如果用int型,那得到的结果可能会有误差,所以我是用double型做的

代码:

#include<stdio.h>#include<algorithm>using namespace std;int main(){    double n;    while(~scanf("%lf",&n))    {        double m=0;        if(n==0)            break;        if(n>5000000)            m=n-n*0.2;        else if(n>1000000)            m=n-n*0.1;        else            m=n;        printf("%.0lf\n",m);    }    return 0;}