| ||||||||||
| 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:1001为什么是Compile Error? 新人跪求! 源代码奉上。。望解答。In Reply To:1001为什么是Compile Error? 新人跪求! 源代码奉上。。望解答。 Posted by:13xiaobang at 2009-12-07 15:16:18 > //自己的机器上VC6.0运行一点问题也没有,这是为什么?
>
>
> #include "iostream"
> #include "string"
> #include "math.h"
> using namespace std;
>
> string calone(string Num1,int ch2)
> {
> char a[1];
> int ch1;
> string ans;
> int tempans;
> int flag=0;
> int length=Num1.length();
> for(int i=0;i<length;i++)
> {
> ch1=Num1.at(length-1-i)-48;
> if(flag+ch1*ch2<10)
> {
> tempans=flag+ch1*ch2;
> flag=0;
> }
> else
> {
> tempans=(flag+ch1*ch2)%10;
> flag=(flag+ch1*ch2-tempans)/10;
> }
> ans=itoa(tempans,a,10)+ans;
> }
> if(flag!=0)
> ans=itoa(flag,a,10)+ans;
> return ans;
> }
>
> string addNum(string Num1,string Num2)
> {
> int length1 = Num1.length();
> int length2 = Num2.length();
> int tempans=0;
> int chaju=abs(length1-length2);
> string ans;
> int flag=0;
> int length=0;
> char a[1];
> int i=0;
> if(length1>length2)
> {
> length=length2;
> for( i=0;i<length;i++)
> {
> tempans=Num1.at(length+chaju-1-i)-48+Num2.at(length-1-i)-48+flag;
> if(tempans>9)
> {
> flag=1;
> tempans-=10;
> }
> else
> {
> flag=0;
> }
> ans=itoa(tempans,a,10)+ans;
> }
> for(;i<length1;i++)
> {
> tempans=Num1.at(length+chaju-1-i)-48+flag;
> flag=0;
> ans = itoa(tempans,a,10)+ans;
> }
> if(flag)
> ans=itoa(flag,a,10)+ans;
> return ans;
> }
> else
> {
> length=length1;
> for( i=0;i<length;i++)
> {
> tempans=Num1.at(length-1-i)-48+Num2.at(length+chaju-1-i)-48+flag;
> if(tempans>9)
> {
> flag=1;
> tempans-=10;
> }
> else
> {
> flag=0;
> }
> ans=itoa(tempans,a,10)+ans;
> }
> for(;i<length2;i++)
> {
> tempans=Num2.at(length+chaju-1-i)-48+flag;
> flag=0;
> ans = itoa(tempans,a,10)+ans;
> }
> if(flag)
> ans=itoa(flag,a,10)+ans;
> return ans;
> }
> }
>
> string caltwo(string Num1,string Num2)
> {
> int length2 = Num2.length();
> string zero="";
> if(length2==1)
> return calone(Num1,Num2.at(0)-48);
> else
> {
> string ans="0";
> for(int i = 0;i<length2;i++)
> {
> zero="";
> for(int j=0;j<i;j++)
> zero=zero+'0';
> ans=addNum(ans,calone(Num1,Num2.at(length2-1-i)-48)+zero);
> }
> return ans;
> }
>
> }
>
> int main()
> {
> string Num1;
> int wei=0;
> string s1;
> int n;
> int length;
> string ans;
> string bei;
> bool flag=0;
> while(cin>>Num1>>n)
> {
> length=Num1.length();
> while(Num1.at(length-1)=='0')
> {
> length--;
> Num1.erase(length);
> }
> s1=Num1;
> wei = s1.find_first_of('.',0);
> wei=length-wei-1;
> s1.erase(length-wei-1,1);
> bei=s1;
> ans=s1;
> for(int j=0;j<n-1;j++)
> ans=caltwo(ans,bei);
> int anslength = ans.length();
> ans.insert(anslength-wei*n,1,'.');
> cout<<ans<<endl;
> wei=0;
> length=0;
> }
> return 0;
> }
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator