求高精度幂

#include<iostream>
using namespace std;
int main()
{
double R[5];
int n[5];
double sum=1;
for(int i=0;i<6;i++)
{
cin>>R[i];
cin>>n[i];
}
for(i=0;i<6;i++)
{
for(int j=0;j<n[i];j++)
{
            sum=sum*R[i];
}
        cout<<sum<<endl;
sum=1;
}
getchar();
}
阅读更多

acm 求高精度

09-23

http://acm.pku.edu.cn/JudgeOnline/problem?id=1001&lang=zh-CN&change=true (原题地址)rn我的代码 对例子 测试都正确 以及对讨论的中例子也正确 但通不过 郁闷 wrong answerrn测试数据rn95.123 12rn0.4321 20rn5.1234 15rn6.7592 9rn98.999 10rn1.0100 12rn.00001 1rn.12345 1rn0001.1 1rn1.1000 1rn10.000 1rn000.10 1rn000000 1rn000.00 1rn.00000 0rn000010 1rn000.10 1rn0000.1 1rn00.111 1rnrn0.0001 1rn0.0001 3rn0.0010 1rn0.0010 3rn0.0100 1rn0.0100 3rn0.1000 1rn0.1000 3rn1.0000 1rn1.0000 3rn1.0001 1rn1.0001 3rn1.0010 1rn1.0010 3rn1.0100 1rn1.0100 3rn1.1000 1rn1.1000 3rn10.000 1rn10.000 3rn10.001 1rn10.001 3rn10.010 1rn10.010 3rn10.100 1rn10.100 3rn99.000 1rn99.000 3rn99.001 1rn99.001 3rn99.010 1rn99.010 3rn99.100 1rn99.100 3rn99.998 1rn99.998 3rnrn#includern#includern#includern#includern#includernusing namespace std;rnint main()rnrn string str;int n; int carry=0;int remain;vector result1;vector a;int z=0;bool bl=true;rn rn vector *b=new vector();;int k=0;int q=0;vector *result2;rn vector::iterator it;vector::iterator itt;vector::iterator add;vector::iterator add2;rn while(cin>>str>>n)rn b->clear();a.clear();k=0;q=0;z=0;carry=0;bl=true;rn result1.clear();rn for(int i=str.length()-1;i>=0;i--) //标准化数组 把小数位数放如k,或 10的位数放入zrn rn if(str[i]=='.')k=str.length()-1-i-z;z=0;continue;rn if(str[i]=='0'&&bl)z=z+1;continue;rn bl=false;rn a.push_back((str[i]-'0'));b->push_back((str[i]-'0')); //a=b=Rrn rn rn k=n*k;z=z*n; //计算幂次后小数位数k 或10rn for(int i=0;i*pp=new vector();rn result2=pp;rn for(it=(a.begin());it!=(a.end());++it)rn rn rn for(itt=b->begin();itt!=b->end();++itt)rn rn if(q==0)result2->push_back(0);rn remain=((*it)*(*itt)+carry)%10;rnrn carry=((*it)*(*itt)+carry)/10;rn result1.push_back(remain);rn rn if(carry)result1.push_back(carry);rn add2=result2->begin()+q;carry=0;rn rn for(add=result1.begin();add!=result1.end();++add)rn rn if(add2==(result2->end()))result2->push_back(0);add2=(result2->end()-1);rn remain=((*add)+(*add2)+carry)%10;rn carry=((*add)+(*add2)+carry)/10;rn (*add2)=remain;rn add2+=1;rn rn if(carry)result2->push_back(carry);rn q=q+1;carry=0;result1.clear();rn rn delete b;rn b=result2;rn q=0;rnrn rn int i=0; //输出 rnrn for(add=b->end();add!=b->begin();add--)rn rn if(i==(b->size()-k))cout<<"."<

没有更多推荐了,返回首页