• TZOJ--4212: Buy Candy (模拟)


    4212: Buy Candy 

    时间限制(普通/Java):1000MS/3000MS     内存限制:65536KByte

    描述

    Mirko buys a lot of candy in the candy shop. He cannot always pay the exact amount so the shopkeeper and he have an agreement. He tells the shopkeeper the smallest bill he has, and she rounds his ammount to the nearest number he can pay. For example, if the smallest bill Mirko has is a hundred bill, and he wants to buy 150 Kunas of candy, the shopkeeper rounds his amount to 200 Kunas. If he wants to buy 149 Kunas of candy, the shopkeeper rounds his amount to 100 Kunas.

    Lately, Mirko suspects the shoopkeeper is trying to cheat him. He asked you to help him. Write a program that will help him.

    His mother only gives Mirko 1, 10, 100, 1 000, ... , 1 000 000 000 Kuna bills. He never has bills that are not powers of 10. The bills he does have, he has in large amounts.

    输入

    The first and only line of input contains two integers, C (0 <= C <=1 000 000 000), the price of candy Mirko is going to buy, and K (0 <= K <= 9), number of zeros on the smallest bill Mirko has.

    输出

    The first and only line of output should contain one integer, C rounded to the nearest amount Mirko can pay.

    样例输入

     184 1

    样例输出

     180

    题目来源

    TOJ

     

    题目链接:http://tzcoder.cn/acmhome/problemdetail.do?&method=showdetail&id=4212

     

    题目大意:给你一个数C,要求对C的最后K为进行四舍五入

    模拟一下第k位,判断是一些是否大于4

     

    ?
    #include <bits/stdc++.h>
    using namespace std;
    #define LL __int64
    int main()
    {
    	LL a,k,i,u,q;
    	while(~scanf("%I64d %I64d",&a,&k))
    	{
    		for(i=0,u=1;i<k;i++)u*=10;
    		q=a%u;
    		a-=q;
    		if(q*10/u>4)a+=u;
    		printf("%I64d
    ",a);
    	}
    	return 0;
    } 
    

      

  • 相关阅读:
    Flink CEP实例及基础应用
    seata 分布式事务
    skywalking 分布式链路追踪
    datax 离线数据同步工具
    rocketmq 消息队列
    Nacos 服务注册
    跨站(cross-site)、跨域(cross-origin)、SameSite与XMLHttpRequest.withCredentials
    读写二进制文件与文本文件
    WPF中通过双击编辑DataGrid中Cell(附源码)
    记一次XML文件读取优化
  • 原文地址:https://www.cnblogs.com/Anidlebrain/p/10059257.html
Copyright © 2020-2023  润新知