TXT

# 1001 Exponentiation

By Diana Sanchez,2014-03-24 13:52
6 views 0
1001 Exponentiation

Source Code

Problem: 1001 User: * Memory: 32K Time: 0MS Language: C++ Result: Accepted

* Source Code

#include <iostream.h>

int main()

{

char r[7]; //要输入六位数据

int n,i,j,s;

//unsigned long a,b,c;

int a,b,c;

//for(i=0;i<6;i++)

//cin>>r[i]>>n[i]; //输入数据

//if(cin.eof()) return 0;

while(cin>>r>>n){

//for(z=0;z<6;z++){

const int l=150;

//unsigned long A[l];

//unsigned long B[l];

int A[l];

int B[l];

for(j=0;j<l;j++){

A[j]='n';

B[j]='n';

}

//unsigned long X;

int X;

//unsigned long temp;

//unsigned long ss;

int temp;

int ss;

int w=0,y=0;

ss=r[0]-48;

for(i=1;i<6;i++){

if(r[i]=='.') w=1;

else{

ss=ss*10+(r[i]-48);//把小数变成整数

if(w==1) y++;//计算小数点的位数

}

}

X=ss;

A[0]=1;

for(s=0;s<n;s++){

j=0;

while(A[j]!='n'){//逐位相乘

temp=A[j]*X;

c=j;

while(temp>=10){//十进位

a=temp%10;

if(B[c]=='n')

B[c]=a;

else{

B[c]=B[c]+a;

}

temp=temp/10;

c++;

}

if(B[c]=='n')//把积加入数组

B[c]=temp;

else{

B[c]=B[c]+temp;

}

int ip;

for(ip=0;ip<l;ip++){//十进位

if(B[ip]=='n') break;

if(B[ip]>=10){

if(B[ip+1]=='n') B[ip+1]=B[ip]/10;

else B[ip+1]=B[ip+1]+B[ip]/10;

B[ip]=B[ip]%10;

}

}

j++;

}//计算结束

int is,js;

for(is=0;is<l;is++){

if(B[is]=='n') break;

A[is]=B[is];

B[is]='n';

}

for(is=0;is<l;is++){

if(A[is]=='n') break;

if(A[is]>=10){

if(A[is+1]=='n') A[is+1]=A[is]/10;

else A[is+1]=A[is+1]+A[is]/10;

A[is]=A[is]%10;

}

}

}

for(j=0;j<l;j++){

if(A[j]=='n'){

break;

}

}

if(j<y*n){//不足小数位补零

for(;j<y*n;j++)

{

A[j]=0;

}

}

char tt='o',tb;

for(i=y*n;i<l;i++){//加入小数点为

tb=A[i];

A[i]=tt;

tt=tb;

if(tt=='n') break;

}

int iq;

for(iq=0;iq<l;iq++){

if(A[iq]!=0){

break;

}

}

if(A[iq]=='o') iq++;

for(i=j;i>=iq;i--){

if(A[i]=='o') cout<<".";

else

cout<<A[i];

}

cout<<endl;

//}

}

return 0;

}

Report this document

For any questions or suggestions please email
cust-service@docsford.com