Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

个人编的程序,觉得没毛病,为什么WA

Posted by 2018111344 at 2019-01-17 21:28:02 on Problem 1001
#include <iostream>
#include <cstring>
#include <string>

using namespace std;
string s;
int n;
class lint
{
private:
    int a[100];
    int _10fu;
    int n;
    int begin;
    bool isint;
    void clean()
    {
        while(a[n]==0&&n>0) n--;
        int i=1;
        while(a[i]==0) i++;
        if(i>_10fu) isint=true;
        while(a[begin]==0&&begin<=_10fu){
        	begin++;
		} 
    }
public:
    lint()
    {
        ;
    }
    lint(string s)
    {	
        begin=1;
        isint=false;
    	memset(a,0,sizeof(a));
        n=s.size()-1;
        _10fu=n-s.find('.');
        if(s.find('.')!=-1)
        {
        for(int i=0,j=0;i<=n;i++)
        {
            char ch;
            ch=s[i];
            if(ch=='.') continue;
            a[n-j]=ch-'0';
            j++;
        }
    }
        else {
        	_10fu=0;
        	n++;
        	for(int i=0;i<n;i++)
        	{
        		a[n-i]=s[i]-'0';
			}
		}
        clean();
    }
    void mul(const lint &x,const lint & y)
    {
    	int b[101];
    	memset(b,0,sizeof(b));
        n=x.n+y.n;
        for(int i=1;i<=x.n;i++)
            for(int j=1;j<=y.n;j++)
            {
                b[i+j-1]+=x.a[i]*y.a[j];
            }
        for(int i=1;i<=n;i++)
        {
            b[i+1]+=b[i]/10;
            b[i]%=10;
        }
        for(int i=1;i<=n;i++)
        {
        	a[i]=b[i];
		}
		_10fu=x._10fu+y._10fu;
        clean();

    }
    void show()
    {
    	if(n==0) cout<<0;
        for(int i=max(n,_10fu);i>=begin;i--)
        {
            if(i==_10fu) 
			{if(!isint)
			cout<<'.';
			else break;
		}
		
            cout<<a[i];
        }
    }
};

int main()
{
    while(cin>>s>>n)
    {
        lint a,ans;
        a=s;
        ans=s;
        for(int i=2;i<=n;i++)
        {
            ans.mul(ans,a);
        }
        ans.show();
        cout<<endl;
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator