[ create a new paste ] login | about

Link: http://codepad.org/lABYq6CJ    [ raw code | output | fork ]

iamyeasin - C++, pasted on Mar 14:
#include<bits/stdc++.h>

using namespace std;

void rev(char *from,char *to)
{
    int len = strlen(from);
    int l;

    for(l=0; l<len; l++)
    {
        to[l] = from[len-l-1];
    }
    to[len] = '\0';
}

void callMult(char *first,char *sec,char *result)
{

    char F[10000],S[10000],temp[10000];
    int f_len,s_len,f,s,r,t_len,hold,res;
    f_len = strlen(first);
    s_len = strlen(sec);

    rev(first,F);
    rev(sec,S);

//    cout<<F<<" "<<S<<endl;
    t_len = f_len + s_len;
    r = -1;

    for(f=0; f <= t_len; f++)
    {
        temp[f] = '0';
    }

    temp[f] = '\0';

    for(s = 0; s<s_len; s++)
    {
        hold = 0;
        for(f = 0; f<f_len; f++)
        {
            res = (F[f] - '0')*(S[s]-'0')+hold+(temp[f+s]-'0');
            temp[f+s] = res % 10 + '0';
            hold = res/10;
            if(f+s>r) {r = f+s;}
        }

        while(hold != 0)
        {
            res = hold + temp[f+s] - '0';
            hold = res / 10;
            temp[f+s] = res % 10 + '0';
            if(r<f+s) r = f+s;
                f++;

        }
    }



    for(; r>0 && temp[r] == '\0' ; r--);
    temp[r+1] = '\0';
    rev(temp,result);

//      cout<<result<<" "<<temp<<endl;
}


int main()
{
//    freopen("in.txt","rt",stdin);
//    freopen("out.txt","wt",stdout);


    char fir[100000],sec[100000],res[100000];

    while(scanf("%s %s",&fir,&sec) != EOF)
    {
        callMult(fir,sec,res);
        int len = strlen(res);
        int flag = 0;
        for(int i=0; i<len; i++)
        {
            if(res[i] != '0')
            {
                flag = 1;
            }
        }

        if(flag)
        {
            printf("%s\n",res);
        }
        else
        {
            printf("0\n");
        }

//        for(int i=0; i<len; i++)
//        {
//            printf("%c",res[i]);
//        }
//    cout<<res<<endl;

    }

    return 0;
}


Output:
1
2
3
4
5
Line 23: error: bits/stdc++.h: No such file or directory
cc1plus: warnings being treated as errors
In function 'int main()':
Line 79: warning: format '%s' expects type 'char*', but argument 2 has type 'char (*)[100000]'
Line 79: warning: format '%s' expects type 'char*', but argument 3 has type 'char (*)[100000]'


Create a new paste based on this one


Comments: