Discount

Discount


Time Limit:1sMemory limit:32M
Accepted Submit:54Total Submit:117

Problem Description

People like to buy gifts in discount. For example, gift A with initial price RMB50, 30% off actually costsRMB35, gift B with initial price RMB104, 17% off actually costs RMB86.32.
Mr.Richman is a rich man. He hates small money, so he always pays an integer number of RMBs without getting any change. What's more, being a traditional Chinese person, the amount of money he pays always contains the lucky digit '8' (of course, the integer MUST be at least the actual price after discount). For example, he would pay RMB38 for gift A, and RMB87 for gift B.
Given the initial price and the discount for a gift, calculate how much Mr.Richman would like to pay.

Input

The first line contains t (1 ≤ t ≤ 20), the number of test cases followed. Each line contains two integers P and D(1 ≤ P ≤ 500, 1 ≤ D ≤ 99), the initial price and discount.

OutPut

For each test case, print the amount of money Mr.Richman would like to pay.

Sample Input

5 
50 30 
104 17 
500 4 
498 6 
40 5

Sample Output

38
87
480
478
38

Original: 2009 NIT Cup National Invitation Contest Practice Session

 

http://acm.fzu.edu.cn/problem.php?pid=1773

 

这一题是一种求一个数中是否含有某个数,这题里面求的是是否含有8这个数,比如448458380,如果没有,那就从个位逐渐加1,直到加最少的数就使这个数含有数字8。本程序的思想是这样的,用一个数组存放这个数的每一位:个位,十位,百位。然后一位一位的判断是否含有数字8,如果没有个位的数就加1,有点类似于高精度的加减法。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值