• Multiplication 3 AtCoder


    Problem Statement
    Compute A×B, truncate its fractional part, and print the result as an integer.

    Input
    Input is given from Standard Input in the following format:

    A B

    OUTPUT

    A*B

    这里的B是不超过10的两位浮点数。

    A的取值范围是1e15.?

    题解:浮点数精度,也就是如果用long double或者double直接乘的话long long 的话,这最后几位可能会有差错。用字符串来保存B然后将B弄乘以100化成整数,最后在除以100就好了(但是double 的精度明明为15~16位,long double 应该会更加精确,为什么还会爆精度呢?)

    code:

    #include<bits/stdc++.h>
    using namespace std;
    char s[10];
    int main(){
        long long x;
        cin>>x;
        cin>>s;
        long long y;
        y=(s[0]-'0')*100+(s[2]-'0')*10+(s[3]-'0');
        long long z=x*y/100;
        printf("%lld
    ",z); 
        return 0;
    } 
  • 相关阅读:
    装饰器
    内置函数
    文件操作
    函数
    数据结构[总结笔记]
    汉诺塔解题思路
    springboot事物
    mysql5.7.29 zip包安装教程
    mysql常用语句【转载】
    springboot+mysql+jpa+sharding-jdbc+druid读写分离
  • 原文地址:https://www.cnblogs.com/Accepting/p/13084178.html
Copyright © 2020-2023  润新知