| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:测试数组全过 但就是WAIn Reply To:测试数组全过 但就是WA Posted by:namewchwch at 2009-09-23 11:52:49 > #include<iostream>
> #include<string>
> #include<vector>
> #include<algorithm>
> #include<sstream>
> using namespace std;
> int main()
> {
> string str;int n; int carry=0;int remain;vector<int> result1;vector<int> a;int z=0;bool bl=true;
>
> vector<int> *b=new vector<int>();;int k=0;int q=0;vector<int> *result2;
> vector<int>::iterator it;vector<int>::iterator itt;vector<int>::iterator add;vector<int>::iterator add2;
> while(cin>>str>>n)
> { b->clear();a.clear();k=0;q=0;z=0;carry=0;bl=true;
> result1.clear();
> for(int i=str.length()-1;i>=0;i--) //标准化数组 把小数位数放如k,或 10的位数放入z
> {
> if(str[i]=='.'){k=str.length()-1-i-z;z=0;continue;}
> if(str[i]=='0'&&bl){z=z+1;continue;}
> bl=false;
> a.push_back((str[i]-'0'));b->push_back((str[i]-'0')); //a=b=R
>
> }
> k=n*k;z=z*n; //计算幂次后小数位数k 或10
> for(int i=0;i<n-1;i++) //b=R乘以R n-1次
> {
>
> vector<int>*pp=new vector<int>();
> result2=pp;
> for(it=(a.begin());it!=(a.end());++it)
> {
>
> for(itt=b->begin();itt!=b->end();++itt)
> {
> if(q==0){result2->push_back(0);}
> remain=((*it)*(*itt)+carry)%10;
>
> carry=((*it)*(*itt)+carry)/10;
> result1.push_back(remain);
> }
> if(carry){result1.push_back(carry);}
> add2=result2->begin()+q;carry=0;
>
> for(add=result1.begin();add!=result1.end();++add)
> {
> if(add2==(result2->end())){result2->push_back(0);add2=(result2->end()-1);}
> remain=((*add)+(*add2)+carry)%10;
> carry=((*add)+(*add2)+carry)/10;
> (*add2)=remain;
> add2+=1;
> }
> if(carry){result2->push_back(carry);}
> q=q+1;carry=0;result1.clear();
> }
> delete b;
> b=result2;
> q=0;
>
> }
> int i=0; //输出
>
> for(add=b->end();add!=b->begin();add--)
> {
> if(i==(b->size()-k))cout<<"."<<flush;
> cout<<*(add-1)<<flush;
> i=i+1;
>
>
> }
> while(z)
> {
> cout<<"0"<<flush;
> z=z-1;
> }
> if(!z) cout<<"\n";
>
> }
> return 0;
> }
>
>
> 那位高手 指点下啊
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator