Why My Code Falls For [Big Sum]

Dev Skill archived problems can be discussed here.

Why My Code Falls For [Big Sum]

by sakib1061 » Thu Mar 17, 2016 12:58 pm

Code: Select all
/***********************************\
        BOXTROLL
        Sakibhossain.nstu@gmail.com
/************************************/
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define vip(A) vector<pair<int,int> >A
#define ulta(A) reverse(all(A))
#define pai(A) pair<int,int>A
#define mkp(x,y) make_pair(x,y)
#define ll long long int
#define ull unsigned long long int
#define re(x) return x
#define repa(i,j) for(i=1;i<=j;i++)
#define rep(i,j) for( i=0;i<j;i++)
#define pob pop_back()
#define per(i,j) for(int i=j;i>=0;i--)
#define po(i,j) pow(i+0.0,j)
#define pb(x) push_back(x)
#define ppb(x,y) push_back(pair<int, int>(x,y))
#define pf printf
#define sf scanf
#define all(x) x.begin(), x.end()
#define clr(x) x.erase(all(x))
#define sum(x) accumulate(all(x),0)
#define vi(x) vector<int>x
#define vs(x) vector<string>x
#define fimax(A) max_element(all(A))
#define fimin(A) min_element(all(A))
#define ca(x) pf("Case %d: ",x)
#define show(A) for(int i=0;i<A.size();i++){cout<<A[i]<<endl;}
#define ok pf("ok\n")
#define SET(x) memset(x, 0, sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
template <class T> T Max(T a, T b) { return a>b?a:b;}
template <class T> T Min(T a, T b) { return a<b?a:b;}
bool stb(const string &a,const string &b) ///sorting from small to big size///
{
    return a.size()<b.size();
}
bool bts(const string &a,const string &b)  ///sorting from big to small size///
{
    return a.size()>b.size();
}
bool pas(const pair< int,int > &a,const pair <int,int> &b) ///Sort by Second elements of Pair ///
{
    return a.ss<b.ss;
}
///Main Code Starting From Here///
int main()
{
string a,b;
vector<char>c;
int i,j,k;
char cc;
while(cin>>cc)
{
    a+=cc;
    while(1)
    {
        cin>>cc;
        if(cc==',')
            break;
        a+=cc;
    }
    cin>>b;


    if(a.size()>b.size())
        for(j=b.size();j<a.size();j++)
        b+='0';
    else if(b.size()>a.size())
        for(j=a.size();j<b.size();j++)
        a+='0';
            reverse(all(a)),reverse(all(b));
            int le=a.size();
            int rem=0;
        for(i=le-1;i>=0;i--)
        {
            int aa=a[i]-48;
            int bb=b[i]-48;
            int dd=(aa+bb+rem)%10;
            rem=(aa+bb+rem)/10.0;
            c.pb(dd+48);
//            cout<<c[c.size()-1]<<endl;
        }
        if(rem>0)
            c.pb(rem+48);
//        reverse(all(c));
        int l=c.size();
        for(j=0;j<l;j++)
            if(c[j]>48)
            break;
        int p=0;
        for(i=j;i<l;i++)
            if(c[i]>=48 && c[i]<57)
            cout<<c[i],p++;
        if(p==0)
            cout<<0;
        cout<<endl;
//        cout<<a<<" "<<b<<endl;
    clr(a),clr(b),clr(c);
}
return 0;
}
///Never Give Up///


:(
 
Posts: 2
Joined: Thu Mar 17, 2016 12:55 pm

Re: Why My Code Falls For [Big Sum]

by devskill » Tue Jul 19, 2016 11:38 pm

Try this input / output

Input:
Code: Select all
476778555271403714551563144013340466330337360,782337475370353354182003536422310334266486407607607217677870105386002708658450


Output:
Code: Select all
169016031642756078634566670535650790696714867607607217677870105386002708658450
User avatar
Site Admin
 
Posts: 118
Joined: Tue Feb 02, 2016 10:24 pm

Re: Why My Code Falls For [Big Sum]

by sakib1061 » Wed Aug 31, 2016 11:10 pm

Yap accepted
 
Posts: 2
Joined: Thu Mar 17, 2016 12:55 pm


Who is online
Users browsing this forum: No registered users and 1 guest
cron