PKU OJ的一道题目--Exponentiation(ID:1001)????????

hua_zhixing_ 2009-04-12 08:08:12
哪位做出来啦??最后的数据不知道怎么处理,而且我做出来的结果根本没那么大的精度。
Exponentiation
Time Limit: 500MS Memory Limit: 10000K
Total Submissions: 47367 Accepted: 10904

Description

Problems involving the computation of exact values of very large magnitude(['mæɡnitju:d],大小, 积, 量, 长(度)) and precision([pri'siӡən],精确(性); 精密(度)) are common. For example, the computation of the national debt is a taxing experience for many computer systems.

This problem requires that you write a program to compute the exact value of Rn where R is a real number ( 0.0 < R < 99.999 ) and n is an integer such that 0 < n <= 25.

Input

The input will consist of a set of pairs of values for R and n. The R value will occupy columns(['kɔləm]圆柱, 柱壮物,专栏) 1 through 6, and the n value will be in columns 8 and 9.

Output

The output will consist of one line for each line of input giving the exact value of R^n. Leading zeros should be suppressed([sə'pres],止住,不让发表 )in the output. Insignificant([͵insiɡ'nifikənt]无意义的; 无关重要的; 无用的) trailing([treil]痕迹, 足迹,一串, 一系列) zeros must not be printed. Don't print the decimal(['desiməl]以十作基础的, 十进位的, 小数的) point if the result is an integer.
Sample Input

95.123 12
0.4321 20
5.1234 15
6.7592 9
98.999 10
1.0100 12

Sample Output

548815620517731830194541.899025343415715973535967221869852721
.00000005148554641076956121994511276767154838481760200726351203835429763013462401
43992025569.928573701266488041146654993318703707511666295476720493953024
29448126.764121021618164430206909037173276672
90429072743629540498.107596019456651774561044010001
1.126825030131969720661201
...全文
167 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuyang19890710 2011-09-06
  • 打赏
  • 举报
回复
大哥,你写的代码一行注释都麽有,让人情何以堪。
//[Quote=引用 1 楼 liao05050075 的回复:]
这题目的输出很麻烦。我改了两次输出才搞定的
下面是我的代码。

C/C++ code

#include<stdio.h>
#include<string.h>

int main()
{
char s[7];
int n,lena,decp;
char b[500],c[500];
lab1: while(s……
[/Quote]
liao05050075 2009-04-12
  • 打赏
  • 举报
回复
这题目的输出很麻烦。我改了两次输出才搞定的
下面是我的代码。

#include<stdio.h>
#include<string.h>

int main()
{
char s[7];
int n,lena,decp;
char b[500],c[500];
lab1: while(scanf("%s%d",s,&n)>0)
{
char a[500]={0};
if(!strcmp(s,"0.0000")) {printf("0\n");goto lab1;}
strrev(s);
int i=0,j=0;
while(s[i]=='0') i++;
while(i&&i<(int)strlen(s)+1)
s[j++]=s[i++];
i=0;
int len=strlen(s);
while(s[i]!='.') i++;
decp=i*n;
for(;i<=len;i++) s[i]=s[i+1];
len--;
for(i=0;i<len;i++) {s[i]-=48;a[i]=s[i];}
lena=len;
int k=0;

int t;
while(--n)
{
t=0;
int tmp=0;
for(j=0;j<500;j++) c[j]=0;
for(i=0;i<len;i++)
{ if(!s[i]) goto lab;
for(j=0;j<500;j++) b[j]=0;
tmp=0;
for(j=0;j<lena;j++)
{
b[j+t]=s[i]*a[j]+tmp;
tmp=0;
if(b[j+t]>9)
{
tmp=b[j+t]/10;
b[j+t]%=10;
}
}
if(tmp) b[j+t]=tmp;
for(k=t;k<=t+lena;k++)
{
c[k]+=b[k];
if(c[k]>9)
{
c[k+1]+=c[k]/10;
c[k]%=10;
}
}
while(c[k]>9)
{
c[k+1]+=c[k]/10;
c[k]%=10;
k++;
}
lab: t++;
}
j=0;
while(j<k) {a[j]=c[j];j++;}
lena=j;
}

//output
while(!a[lena]) lena--;
if(decp>lena)
{
printf(".");
for(i=decp-lena-1;i>0;i--) printf("0");
while(lena)
printf("%d",a[lena--]);
printf("%d\n",a[0]);
}
else
{
for(i=lena;i>=0;i--)
if(i==decp&&decp!=0) printf("%d.",a[i]);
else printf("%d",a[i]);
printf("\n");
}

}
return 0;
}

liao05050075 2009-04-12
  • 打赏
  • 举报
回复
这题目的输出很麻烦。我改了两次输出才搞定的
下面是我的代码。

#include<stdio.h>
#include<string.h>

int main()
{
char s[7];
int n,lena,decp;
char b[500],c[500];
lab1: while(scanf("%s%d",s,&n)>0)
{
char a[500]={0};
if(!strcmp(s,"0.0000")) {printf("0\n");goto lab1;}
strrev(s);
int i=0,j=0;
while(s[i]=='0') i++;
while(i&&i<(int)strlen(s)+1)
s[j++]=s[i++];
i=0;
int len=strlen(s);
while(s[i]!='.') i++;
decp=i*n;
for(;i<=len;i++) s[i]=s[i+1];
len--;
for(i=0;i<len;i++) {s[i]-=48;a[i]=s[i];}
lena=len;
int k=0;

int t;
while(--n)
{
t=0;
int tmp=0;
for(j=0;j<500;j++) c[j]=0;
for(i=0;i<len;i++)
{ if(!s[i]) goto lab;
for(j=0;j<500;j++) b[j]=0;
tmp=0;
for(j=0;j<lena;j++)
{
b[j+t]=s[i]*a[j]+tmp;
tmp=0;
if(b[j+t]>9)
{
tmp=b[j+t]/10;
b[j+t]%=10;
}
}
if(tmp) b[j+t]=tmp;
for(k=t;k<=t+lena;k++)
{
c[k]+=b[k];
if(c[k]>9)
{
c[k+1]+=c[k]/10;
c[k]%=10;
}
}
while(c[k]>9)
{
c[k+1]+=c[k]/10;
c[k]%=10;
k++;
}
lab: t++;
}
j=0;
while(j<k) {a[j]=c[j];j++;}
lena=j;
}

//output
while(!a[lena]) lena--;
if(decp>lena)
{
printf(".");
for(i=decp-lena-1;i>0;i--) printf("0");
while(lena)
printf("%d",a[lena--]);
printf("%d\n",a[0]);
}
else
{
for(i=lena;i>=0;i--)
if(i==decp&&decp!=0) printf("%d.",a[i]);
else printf("%d",a[i]);
printf("\n");
}

}
return 0;
}

64,646

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧