2235 Discount on Tickets

Source: Internet
Author: User

Title Description Description

Enter the original ticket price (positive integer 3 to 4 digits, Unit: yuan), and then enter the ticket discount rate (up to one digit after the decimal point). program calculates the actual price of the ticket after discount (unit: Yuan. The result of the calculation is to round the single digit to the 10-digit "element". The input is only a single row of two numbers (two spaces separated by a space), the first is an integer, the ticket price, the second integer or real number (as real, up to 1 digits after the decimal point) represents the discount rate.

Input Sample 1:

888 7

Output Example 1:

620

Input Sample 2:

1255 7

Output Example 2:

880

Enter a description Input Description

The input is only a single row of two numbers (two spaces separated by a space), the first is an integer, the ticket price, the second integer or real number (as real, up to 1 digits after the decimal point) represents the discount rate.

Output description Output Description

The output is only a single positive integer representing the discounted ticket price.

Sample input Sample Input

888 7

Sample output Sample Output

620

Data range and Tips Data Size & Hint

The original ticket price is greater than 100 less than 9999, the discount rate is greater than 1 less than 9.9.

Idea: Because rounding starts from the bit, the fractional part doesn't have to be considered. The integer portion of the product is received with the INT variable.

Then is rounding the problem, the single digit is greater than equal to 5 o'clock, to 10 digits into 1, then need to determine whether the 10-digit number needs to be rounded. This defines a flag flag with the initial bit 0, which indicates that no rounding is required.

The number on each bit must be considered only if the single digit is greater than or equal to 5. When rounding is required, the flag is set to 1, which indicates that its previous number needs to be added 1, and the need for rounding is also determined.

Code:

#include <stdio.h>
int main ()
{
Double Price,discount;
int result,len=0,i;
int s[10];
scanf ("%lf%lf", &price,&discount);
result= (int) (PRICE*DISCOUNT/10);
while (result)
{
s[len++]=result%10;
result/=10;
}
int flag=0;
for (i=0;i<len;i++)
{
if (i==0)
{
if (s[i]>=5)
{
flag=1;
}
s[i]=0;
}
Else
{
if (flag==1)
{
S[i]+=flag;
if (s[i]>9)
{
s[i]-=10;
}
Else
{
flag=0;
}
}
}
}
for (i=len-1;i>0;i--)
{
printf ("%d", s[i]);
}
printf ("%d\n", S[i]);
return 0;
}

2235 Discount on Tickets

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.