1102: ticket refund fee calculation (function topic)
Time limit: 1 Sec Memory Limit: 128 MB
submit: 14583 Resolution: 5164
[state] [submit] [proposition man: admin]
Title Description
2013 onwards, the proportion of ticket refund fee reduction: par car station more than 48 hours before the drive time by 5% per ticket refund fee. Meanwhile, the ticket refund fee calculation method is no longer rounded to units of cells but in units of angle 5: less than 0.25 membered rounding the mantissa is not less than 0.25 and less than 0.75 membered element is 0.5 yuan, is not less than 0.75 yuan into $ 1. Write a function to calculate refunds example assumed refund driving time period more than 48 hours. The following function prototype:
Double CancelFee (Double. Price);
this is a problem if the C / C ++ code delivery submitted only CancelFee function definition part, other content submission, compile error.
Enter
Enter a real number, the ticket face value.
Output
Output a real number, the fee refund, the results to one decimal place.
Enter
106
Output
5.5
One
#include<stdio.h>
double CancelFee(double price)
{
double t,x;
t=price*0.05;
x=(int)t;//强制取整
if(t-x>=0&&t-x<0.25) x+=0;
else if(t-x>=0.25&&t-x<0.75) x+=0.5;
else x+=1;
//printf("%.1lf",x);
return x;
}
int main()
{
double n;
scanf("%lf",&n);
n=Cancelfee(n);
printf("%.1lf")
return 0;
}
two
#include <bits/stdc++.h>
using namespace std;
double CancelFee(double m)
{
int x = m * 5;
int d = x / 100, s = x % 100;
double t;
if(s >= 75)
t = 1;
if(s >= 25 && s < 75)
t = 0.5;
return 1.0 * d + t ;
}
int main()
{
double x ;
scanf("%lf",&x);
double m = CancelFee(x);
printf("%.1f\n",m);
return 0;
}