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

过了你这几组数据还是错了

Posted by xiaojiongzi at 2016-07-25 15:41:36 on Problem 1001
In Reply To:Re:贴一个改了N次才提交上的考虑了所有异常输入输出的代码给大家看看,附上几组测试数据 Posted by:lisanhu at 2016-07-24 18:24:14
#include <iostream>
#include<cstring>
using namespace std;
int la;

void gaocheng(int* a,int* b,int lb)
{
    int i,j;
    //la=string(a).length();
    //lb=string(b).length();
    int* s=new int[150];
    for (i=1;i<=la+lb;i++)
        s[i]=0;
    for (i=1;i<=la;i++)
        for (j=1;j<=lb;j++)
        s[i+j-1]+=a[i]*b[j];
        la=la+lb;
    for (i=1;i<=la;i++)
    {
        s[i+1]+=s[i]/10;
        a[i]=s[i]%10;
    }
    while (a[la]==0)
        la--;
        delete[] s;
}

int main()
{
    char m[15];
    int n,l,j,i,k,lb,f,a[150],b[10];
    while (cin>>m>>n)
    {
        k=0;
        l=string(m).length();
        la=1;
        lb=1;
        f=1;
        if (m[0]=='0')
        {
            f=0;
            if (l==1)
            {
                cout<<'0';
                k=1;
            }
        }
        if (n==0)
        {
            cout<<'1';
            k=1;
        }

        if (k==0)
            {
        for(i=l-1;i>=0;i--)
            if (m[i]=='0')
            l--;
        else
            break;
        for (i=l-1;i>=0;i--)
            if (m[i]!='.')
            {
                a[la++]=m[i]-'0';
                b[lb++]=m[i]-'0';
            }
            else
                k=la-1;
                la--;
                lb--;
        if (f==0)
            {
                la--;
                lb--;
            }
                k*=n;
                j=k;
        for (i=0;i<n-1;i++)
            gaocheng(a,b,lb);
        if (f==1)
        for (i=la;i>k;i--)
             cout<<a[i];
        else cout<<'0';
        for (i=1;i<=k;i++)
            if (a[i]==0)
                j--;
            else
                break;
            if (j!=0) cout<<'.';
            if (f==0)
            {
                for(i=1;i<=j-la;i++)
                    cout<<'0';
                for(i=la;i>0;i--)
                    cout<<a[i];
            }
            if(f==1)
             for (i=j;i>0;i--)
               cout<<a[i];
            }
        cout<<endl;
    }
    cout<<a<<endl;
    cout<<b<<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