#include <stdio.h>
#define RATE_ONE 0.03
#define RATE_TWO 0.1
#define RATE_THREE 0.2
#define RATE_FOUR 0.25
#define RATE_FIVE 0.3
#define RATE_SIX 0.35
#define RATE_SEVEN 0.45
#define NUM_TWO 2520
#define NUM_THREE 16920
#define NUM_FOUR 31920
#define NUM_FIVE 52920
#define NUM_SIX 85920
#define NUM_SEVEN 181920
int main(void)
{
double n;
int i = 0;
while (scanf("%lf",&n) != EOF)
{
double m = 0;
if (n > 0 && n <= 36000)
{
m = n * RATE_ONE;
}
else if (n > 36000 && n <= 144000)
{
m = n * RATE_TWO - NUM_TWO;
}
else if (n > 144000 && n <= 300000)
{
m = n * RATE_THREE - NUM_THREE;
}
else if (n > 300000 && n <= 420000)
{
m = n * RATE_FOUR - NUM_FOUR;
}
else if (n > 420000 && n <= 660000)
{
m = n * RATE_FIVE - NUM_FIVE;
}
else if (n > 660000 && n <= 960000)
{
m = n * RATE_SIX - NUM_SIX;
}
else if (n > 960000)
{
m = n * RATE_SEVEN - NUM_SEVEN;
}
printf("%.0lf\n",m);
i++;
if (i == 1000)
break;
}
return 0;
}
书写重复性的代码:
1.注意每一部分代码的共同点,避免小细节上失误,如关系运算符
2.常量较多时最好使用宏定义