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 |
测试数据通过,我自己试的几个数据也通过,但是wa,希望有高手提出意见谢谢,工具,dev-c++#include <iostream> #include <stdlib.h> #include <string> using namespace std; void multi(string&,string&,string&); void predeal(string&,int&,int&); void aftdeal(string&,int&); int main() { string answerlist; string s1,s2,t;int n,k=0; while(cin>>s1>>n) { predeal(s1,k,n); s2=s1; while(n>1) { t.erase(t.begin(),t.end()); multi(s1,s2,t); if (n==2) aftdeal(t,k); for(int x=0;x<t.size();x++) { if (s1.size()>=x+1)s1[x]=t[t.size()-x-1]; else s1+=t[t.size()-x-1]; } s1.erase(s1.begin()+t.size(),s1.end()); n--; } answerlist+=s1; answerlist+='&'; } answerlist+='@'; n=0; while(answerlist[n]!='@') { if(answerlist[n]=='&') cout<<endl; else cout<<answerlist[n]; n++; } system("PAUSE"); return 0; } void multi(string &a,string &b,string &t) { int e,i,j; char t1; for(i=0;i<a.size();i++) { e=0; for(j=0;j<b.size();j++) { if(t.size()<i+j+1) { t+=char(((int(a[a.size()-i-1]-'0'))*(int(b[b.size()-j-1]-'0'))+e)%10+int('0')); e= ((int(a[a.size()-i-1]-'0'))*(int(b[b.size()-j-1]-'0'))+e)/10; } else { t1=t[i+j]; t[i+j]=char((((int(a[a.size()-i-1]-'0'))*(int(b[b.size()-j-1]-'0'))+int(t1-'0')+e)%10)+int('0')); //+=... e= ((int(a[a.size()-i-1]-'0'))*(int(b[b.size()-j-1]-'0'))+int(t1-'0')+e)/10; } } if(e!=0) if(t.size()<i+j+1)t+=char(e+int('0')); } } void predeal(string& s,int& k,int& n) { string::size_type i=s.find('.'); if (i==string::npos) return; k=(s.size()-i-1)*n;//结果后面应该有k位小数 s.erase(i,1); } void aftdeal(string& t,int& k) { t.insert(k,"."); int i=t.size(); while(t[i-1]=='0') i--; if (i<t.size()) t.erase(t.begin()+i,t.end()); i=-1; while(t[i+1]=='0') i++; if(t[i+1]=='.') i++; if (i>=0) t.erase(t.begin(),t.begin()+i+1); } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator