ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1048. Superlong Sums

I don't know what is wrong If you can help i will be very glad to you
Posted by Yrii 12 Feb 2002 02:03
#include<iostream.h>
#define MAX1 112
#define MAX2 1000
    long int n;
    long int *p[MAX1];
    long int *g[MAX1];
    int zap(long int,long int,int);
    long int num(long int,int);
void main(){
    cin >> n;
    for(long int i=0;i<MAX1;i++)
        {
            p[i]=new long int[MAX2];
            g[i]=new long int[MAX2];
        }
    long int pos=0;
    long int l1;
    long int l2;
    long int j;
    long int n0;
    long int sad=0;
    long int TARA=100000000;
    while(pos<n)
        {
            l1=0;
            l2=0;
            long int k=TARA;
            if(n-pos>=9)
                for(j=0;j<9;j++)
                    {
                        cin >> n0;
                        l1=l1+n0*k;
                        cin >> n0;
                        l2=l2+n0*k;
                        k=k/10;
                    }
            else
                for(j=0;j<n-pos;j++)
                    {
                        cin >> n0;
                        l1=l1+n0*k;
                        cin >> n0;
                        l2=l2+n0*k;
                        k=k/10;
                    }
            zap(sad,l1,1);
            zap(sad,l2,2);
            pos=pos+9;
            sad++;
        }
    l2=0;
    for(i=sad-1;i>=0;i--)
        {
          l2=num(i,1)+num(i,2)+l2;
          zap(i,l2%(TARA*10),2);
          l2=l2/(TARA*10);
        }
    pos=0;
    for(i=0;i<sad;i++)
        {
            l2=num(i,2);
            if(n-pos>=9)
                cout << l2;
            else
                {
                    long int k=TARA;
                    for(j=0;j<n-pos;j++)
                        {
                            cout << l2/k;
                            l2=l2-k*
(l2/k);
                            k=k/10;
                        }
                }
            pos=pos+9;
        }

}
long int num(long int pos,int numer){
    for(long int i=0;i<MAX1;i++)
        if((pos>=(long int)(MAX2)*i)&&(pos<(long int)(MAX2)*
(i+1)))
            {
                pos=pos-(long int)(MAX2)*i;
                switch(numer)
                    {
                        case 1:
                            return p[i]
[pos];
                        case 2:
                            return g[i]
[pos];
                    }
            }
    return 0;
}
int zap(long int pos,long int quan,int numer){
    for(long int i=0;i<MAX1;i++)
        if((pos>=(long int)(MAX2)*i)&&(pos<(long int)(MAX2)*
(i+1)))
            {
                pos=pos-(long int)(MAX2)*i;
                switch(numer)
                    {
                        case 1:
                            p[i][pos]
=quan;
                            return 0;
                        case 2:
                            g[i][pos]
=quan;
                            return 0;
                    }
             }
    return 0;
}