北大acm 1001 Exponentiation
来源:互联网 发布:js 添加style属性 编辑:程序博客网 时间:2024/05/21 14:08
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
void mul(int *c,int *a,int *b) //c=a*b
{
int i,j,k,carry,result;
memset(c,0,sizeof(int)*126);
for(j=0,carry=0;j<b[124];j++)
{
for(i=0;i<a[124];i++)
{
k=i+j;
result=b[j]*a[i]+carry+c[k];
c[k]=result%10;
carry=result/10;
}
while(carry)
{
k++;
result=carry+c[k];
carry=result/10;
c[k]=result%10;
}
}
for(i=123;c[i]==0;i--)
c[124]=i;
c[125]=a[125]+b[125];
}
void s2i(char *str,int *a)
{
int n=strlen(str),i,j;
char tmp;
for(i=0,j=n-1;i<j;i++,j--)
{
tmp=str[i];
str[i]=str[j];
str[j]=tmp;
}
for(i=0,a[125]=a[124]=0;str[i]!='.';i++)
{
a[i]=str[i]-'0';
a[125]++;
}
for(i++;i<n;i++)
a[i-1]=str[i]-'0';
a[124]=n-1;
}
int main()
{
int a[126],b[126],c[126],n; //R[125]用来保存小数点,R[124]保存长度
char str[10];
while(cin>>str>>n)
{
s2i(str,a);
memcpy(b,a,126*sizeof(int));
memset(c,0,126*sizeof(int));
c[0]=1;
c[124]=1;
for(int i=1;i<=n;i++)
{
mul(b,c,a);
memcpy(c,b,126*sizeof(int));
}
//output
int i=c[124]-1,j=c[124]-c[125],k;
for(k=0;c[k]==0;k++)
;
if(j<0)
{
printf(".");
while(j<0)
{
printf("0");
j++;
}
while(i>=k)
{
printf("%d",c[i]);
i--;
}
}
else
{
while(i>=k)
{
if(j==0)
printf(".");
j--;
printf("%d",c[i]);
i--;
}
}
printf("\n");
}
return 0;
}
- 北大acm 1001 Exponentiation
- 北大OJ 1001题 Exponentiation
- 北大OJ 1003Hangover && 1001Exponentiation思路
- ACM —— 1001 Exponentiation
- 北大ACM poj 1001
- 北大ACM试题1001
- 北大 ACM 1001 C++实现
- 北大ACM作业练习 1001
- 北大ACM
- ACM HDOJ 1063 (Exponentiation)
- ACM 1001 Exponentiation 高精度幂浮点型的运算
- ACM北大的第1001题
- ACM-北大1001求高精度幂
- 北大OJ 1001题 Exponentiation涉及的效率问题(整型和字符串转换)
- 【北大OJ第二题】Exponentiation(C++)
- 1001 Exponentiation
- 1001 Exponentiation
- 1001 Exponentiation
- Hibernate的save方法源码初探
- 钢笔的保养
- 专
- 深入理解iPhone委托模式兼谈iPhone生命周期(转自DEVDIY论坛)
- Android拨号过程函数调用
- 北大acm 1001 Exponentiation
- mysql默认安装目录说明
- android打电话实现分析
- 23种设计模式的形象比喻
- Objective-C语法快速参考(转自DIVDIY论坛)
- 计算机学生学习资源
- 每对顶点间的最短路径算法时间复杂度改进C++实现
- PHPnow中ZendDebugger与ZendOptimizer 共存
- 苹果每部iPhone4S可赚3917元 开售首日收入39亿元