YunYan

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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\n",z); 
    return 0;
} 

 

posted on 2020-06-10 11:57  Target--fly  阅读(194)  评论(0编辑  收藏  举报