POJ1001:高精度运算程序(X)
2016-07-24 21:41
330 查看
本以为一个高精度乘法是分分钟可以解决的事情,但没想到遇到这种刁难人的测试数据,还真废了点力气。
修改了3次才通过所有数据
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/wronged.gif)
以下为我自己的代码,通过了测试:
0.0010 2
9.9999 4
99.998 3
0.0001 4
1.0000 3
修改了3次才通过所有数据
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/wronged.gif)
15800101 | mollnn | 1001 | Accepted | 772K | 141MS | G++ | 1888B | 2016-07-24 21:37:20 |
#include <iostream> #include <stdio.h> #include <math.h> #define hHRN char* #define HRN(x) char x[200] #define CreateOS() char outs[200] #define nout(x) outs[count++]=x #define a2n(x) x-48 using namespace std; int findLong(int num); int hrMui(hHRN hrn,int mui); void I2H(int source,hHRN hrn); int mOutput(hHRN hrn,int tmpm); // XXX int findLong(int num) { int s=0; int n=num; while(n>0) { ++s; n=n/10; } return s; } int hrMui(hHRN hrn,int mui) { int tmpn; int len; int i; HRN(nhrn); for(i=0;i<200;i++) { nhrn[i]=0; } for(i=199;i>=0;i--) { if(i!=0) break; } len=++i; for(i=0;i<len;i++) { tmpn=hrn[i]*mui; HRN(thrn); for(int j=0;j<200;j++) { thrn[j]=0; } I2H(tmpn,thrn); for(int j=0;j<16;j++) { nhrn[i+j]+=thrn[j]; while(nhrn[i+j]>=10) { nhrn[i+j]-=10; nhrn[i+j+1]++; } } } for(int j=199;j>=0;j--) { hrn[j]=nhrn[j]; } return 0; } void I2H(int source,hHRN hrn) { for(int i=1;i<=16;i++) { hrn[i-1]=source%((int)pow(10,i))/((int)pow(10,i-1)); } } int mOutput(hHRN hrn,int tmpm) { int i,j; char b=0,k=0; for(j=0;j<=199;j++) { if(hrn[j]!=0||((j)==tmpm*5)) break; } for(i=199;i>=0;i--) { if(((i+1)==tmpm*5)&&(!k)) { cout<<"."; b=1; } if(b==0&&hrn[i]!=0) { b=1; } if(b&&i>=j) { cout<<(int)hrn[i]; } if(tmpm*5<=j) { k=1; } } return 0; } int main() { char tmp[6]; int tmpb,tmpm; int i,j; while(cin>>tmp) { int k=0; tmpb=0; for(i=0;i<6;i++) { if(tmp[i]=='.') k=i; } j=100000; i=k; while(--i>=0) { tmpb+=j*(tmp[i]-48); j*=10; } j=10000; i=k; while(++i<6) { tmpb+=j*(tmp[i]-48); j/=10; } cin>>tmpm; HRN(hrn); for(i=0;i<200;i++) { hrn[i]=0; } I2H(tmpb,hrn); for(i=2;i<=tmpm;i++) { hrMui(hrn,tmpb); } int count=0; CreateOS(); mOutput(hrn,tmpm); cout<<endl; } return 0; }另外,提供几个易错的测试数据。如果有朋友的程序调试遇到瓶颈,可供参考:
0.0010 2
9.9999 4
99.998 3
0.0001 4
1.0000 3
相关文章推荐
- 牛顿的三大定律
- 常见的块状和内联元素
- CodeIgniter 3 源码学习笔记《一》
- (磨人的小妖精)hdu 1542 Atlantis:线段树扫描线,离散化
- POJ 1222 EXTENDED LIGHTS OUT熄灯游戏
- 如何创建BFC
- 软技能-John
- C#基础知识(七)——方法重载与out、ref、params参数
- 单态模式
- RDD Transformation —— sample
- bash 基本技巧
- 暑假网页学习1(浮动问题)
- 1、什么是BFC
- javaweb总结
- PostGIS
- 不要在setTimeout中使用字符串
- 《JavaScript高级程序设计》 - 读书笔记 - 第4章 变量、作用域和内存问题
- 插入排序算法之移动交换法
- Node.js+npm安装
- MySQL数据库学习笔记(三)----基本的SQL语句