标签:for out nal 应该 ati div 字符串 pre style
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; }
Multiplication 3 AtCoder - abc169_c (浮点数精度问题)
标签:for out nal 应该 ati div 字符串 pre style
原文地址:https://www.cnblogs.com/Accepting/p/13084178.html