标签:
http://acm.xidian.edu.cn/problem.php?id=1060
这道题真是无语,被坑了好久,刚开始还以为只是浮点数的一点精度问题,在后面加了0.0000001。发现还是一直WA,问题应该是位数太长,后面的精度不准确地太厉害,只好用土方法过了。
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; int a[25]; int main() { long long x; while(~scanf("%lld",&x)) { int cnt = 0; if(x%10 >= 5) x = x/10+1; else x = x/10; if(x == 0) { printf("0.00\n"); continue; } while(x) { a[++cnt] = x%10; x /= 10; } if(cnt > 2) { for(;cnt > 2;cnt--) printf("%d",a[cnt]); } else { printf("0"); } printf("."); if(cnt == 1) printf("0"); for(;cnt > 0;cnt--) printf("%d",a[cnt]); printf("\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zhurb/p/5958758.html