HDOJ 1063 Exponentiation
来源:互联网 发布:csgo优化cfg 编辑:程序博客网 时间:2024/05/25 21:32
大数乘法,过不了只能说明测试用例不完备。贴几组测试用例:
5.1004 15
41120989454.314570363993506408035342551967503175087477761156936917581824
000.10 20
.00000000000000000001
12.010 20
3898164373852177448724.9596914878392975482722144801842193624001
.10000 25
.0000000000000000000000001
110000 20
67274999493256000920100000000000000000000000000000000000000000000000000000000000000000000000000000000
1.0000 25
1
1 0
1
0 1
0
0001.1 1
1.1
然后,就是代码了:
#include<string>#include<memory>using namespace std;#include<math.h>#include<stdio.h>#define DEPTH 1000000000int exponent,value,fractionalLen;__int64 result[25];void multi(){ for(int i=1;i<exponent;i++) { int assist=0; for(int j=1;j<=result[0];j++) { result[j]=result[j]*value+assist; assist=result[j]/DEPTH; result[j]=result[j]%DEPTH; } if(assist>0) { result[0]++; result[result[0]]=assist; } }}int main(){ //freopen("Exponentiation.txt","r",stdin); char vtemp[7]; while(scanf("%s%d",&vtemp,&exponent)!=EOF) { memset(result,0,sizeof(result)); value=0; fractionalLen=0; for(int i=5,cnt=0;i>=0;i--) { if(vtemp[i]>='0'&&vtemp[i]<='9') { value=value+(vtemp[i]-'0')*pow(10.0,cnt); cnt++; } else fractionalLen=5-i; } while(value%10==0&&fractionalLen>0) { value/=10; fractionalLen--; } result[1]=value; result[0]=1; multi(); fractionalLen*=exponent; char assist[10]; sprintf(assist,"%d",result[result[0]]); string answer(assist); int len=(result[0]-1)*9+strlen(assist); for(int i=result[0]-1;i>=0;i--) { sprintf(assist,"%9d",result[i]); answer+=assist; } if(fractionalLen>len) { printf("."); for(int i=fractionalLen-len;i>0;i--) printf("0"); } for(int i=0;i<len;i++) { if(i==len-fractionalLen) printf("."); if(answer[i]==' ') printf("0"); else printf("%c",answer[i]); } printf("\n"); } return 0;}
- HDOJ 1063 Exponentiation
- HDOJ 1063 Exponentiation
- HDOJ 1063 Exponentiation
- ACM HDOJ 1063 (Exponentiation)
- HDOJ 1063 Exponentiation
- HDOJ 1063 Exponentiation
- 【大数问题】 HDOJ 1063 Exponentiation
- hdoj--1063 Exponentiation 解题报告
- hdoj 1063 Exponentiation 【大数精准次幂】
- HDOJ 1063 Exponentiation(小数高精度)
- Exponentiation 1063
- 杭电OJ(HDOJ)1063题:Exponentiation(大数操作——幂运算)
- HDU 1063 Exponentiation&&POJ 1001 Exponentiation
- Exponentiation hdu 1063 java
- HDU 1063 Exponentiation
- hdu 1063 Exponentiation(大数)
- HDU 1063 - Exponentiation
- HDU 1063 Exponentiation
- HDOJ 1061 Rightmost Digit
- 第4章 数组和指针
- cookie 和session 的区别详解
- 应用杀手iOS 5即将消灭的15大应用
- 导出ORACLE中指定的程序包\视图等.
- HDOJ 1063 Exponentiation
- Eclipse3.6与m2eclipse,run-jetty-run插件对WEB项目进行热部署以及在jar源码中进行调试(二)
- 【微博运营】企业微博营销实战流程
- NET程序员,我们应该更专业点
- Eclipse3.6与m2eclipse,run-jetty-run插件对WEB项目进行热部署以及在jar源码中进行调试(三)
- Virtual Audio Cable使用笔记一:使用Virtual Audio Cable将播放器的音频流传输到真实声卡驱动中
- Anders Hejlsberg 访谈 .-转载
- C#.NET中的线程同步类(二)
- 类图理解