压4位的高精度问题-C++最后一点-求教

#include

#include

using namespace std;

int main()

{

string str1,str2;

int a[1000],b[1000],len;

int i;

memset(a,0,sizeof(a));

memset(b,0,sizeof(b));

cin>>str1>>str2;

a[0]=str1.length();

int qqq;

int e;

for(i=1,e=1;i=3)

a[e]=(str1[a[0]-i]-'0')+(str1[a[0]-i-1]-'0')*10+(str1[a[0]-i-2]-'0')*100+(str1[a[0]-i-3]-'0')*1000;

if((a[0]-qqq)==2)

a[e]=(str1[a[0]-i]-'0')+(str1[a[0]-i-1]-'0')*10+(str1[a[0]-i-2]-'0')*100;

if((a[0]-qqq)==1)

a[e]=(str1[a[0]-i]-'0')+(str1[a[0]-i-1]-'0')*10;

if((a[0]-qqq)==0)

a[e]=(str1[a[0]-i]-'0');

}

if(a[0]%4==0)

a[0]=a[0]/4;

else

a[0]=a[0]/4+1;

//b

b[0]=str2.length();

int kkk;

int f;

for(i=1,f=1;i=3)

b[f]=(str2[b[0]-i]-'0')+(str2[b[0]-i-1]-'0')*10+(str2[b[0]-i-2]-'0')*100+(str2[b[0]-i-3]-'0')*1000;

if((b[0]-kkk)==2)

b[f]=(str2[b[0]-i]-'0')+(str2[b[0]-i-1]-'0')*10+(str2[b[0]-i-2]-'0')*100;

if((b[0]-kkk)==1)

b[f]=(str2[b[0]-i]-'0')+(str2[b[0]-i-1]-'0')*10;

if((b[0]-kkk)==0)

b[f]=(str2[b[0]-i]-'0');

}

if(a[0]%4==0)

b[0]=b[0]/4;

else

b[0]=b[0]/4+1;

len=a[0];

int jj;

int c[1000];

for(int j=0;j

1 条评论

  • @ 2015-08-13 10:25:36

    呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子呆子
    #include <cstdio>
    #include <cstring>
    using namespace std;
    struct Bigint
    {
    int n,a[20005];
    Bigint()
    {
    n = 0;
    memset(a,0,sizeof(a));
    }
    void operator = (const char string[10005])
    {
    n = strlen(string);
    for (int i = 0;i < n;i++)
    a[i] = string[n-1-i]-'0';
    }
    Bigint operator * (const Bigint &x)
    {
    Bigint t;t.n = n+x.n-1;
    for (int i = 0;i < n;i++)
    for (int j = 0;j < x.n;j++)
    t.a[i+j] += a[i]*x.a[j];
    for (int i = 0;i < t.n;i++)
    {
    t.a[i+1] += t.a[i] / 10;
    t.a[i] %= 10;
    }
    if (t.a[t.n]) t.n++;
    return t;
    }
    };
    int main()
    {
    char x[10005],y[10005];
    scanf("%s%s",x,y);
    Bigint a,b;
    a = x;
    b = y;
    Bigint ans;
    ans = a*b;
    for (int i = ans.n-1;i >= 0;i--)
    printf("%d",ans.a[i]);
    printf("\n");
    return 0;
    }

  • 1

信息

ID
1040
难度
7
分类
高精度 点击显示
标签
(无)
递交数
16520
已通过
3156
通过率
19%
被复制
24
上传者