#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
char a[1010],b[1010];
int ta[1010],tb[1010];
int main()
{
    int l2,l1,l;
    while(scanf("%s%s",a,b)!=EOF)
    {
        memset(ta,0,sizeof(ta));
        memset(tb,0,sizeof(tb));
        l1=strlen(a);
        l2=strlen(b);
        if(l1<l2)  l=l2;
        else l=l1;
        for(int i=0;i<l;i++)
        {
            if(l1-1>=0)
            {
                ta[i]=a[l1-1]-'0';
                l1--;
            }
            else ta[i]=0;
            if(l2-1>=0)
            {
                tb[i]=b[l2-1]-'0';
                l2--;
            }
            else tb[i]=0;
        }
        int t;
        for(int i=0;i<l;i++)
        {
            t=ta[i]+tb[i];
            if(t>=10)
            {
                ta[i]=t-10;
                ta[i+1]++;
            }
            else ta[i]=t;
        }
        int flag=0;
        for(int i=l;i>=0;i--)
        {
            if(flag||ta[i])
            {
                flag=1;
                printf("%d",ta[i]);
            }
        }
        if(!flag) printf("0");//用于解决只有0相加的状况
        printf("\n");    }
    return 0;
}Integer Inquiry
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
    int l1;
    char a[1001];
    int b[1001];
    memset(b,0,sizeof(b));
    while(scanf("%s",a)!=EOF)
    {
        if(a[0]=='0') break;
        l1=strlen(a);
        int j=0;
        for(int i=l1-1; i>=0; i--)
        {
            b[j]=b[j]+a[i]-'0';
            j++;
        }
    }
    int t;
    for(int i=0; i<1001; i++)
    {
        t=b[i];
        if(b[i]>9)
        {
            b[i]=t%10;
            b[i+1]=b[i+1]+t/10;
        }
        else b[i]=t;
    }
    int flag=0;
    for(int i=1001-1; i>=0; i--)
    {
        if (flag || b[i])
        {
            flag = 1;
            printf("%d",b[i]);
        }
    }
    if (!flag) printf("0");
    printf("\n");
    return 0;
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.

 Product

 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
char str1[300],str2[300];
int d[300],f[300],c[601];
int l1,l2,l,w,e;
void init()
{
    memset(c,0,sizeof(c));
    memset(d,0,sizeof(d));
    memset(f,0,sizeof(f));
}
int main()
{
    while(scanf("%s",str1)!=EOF)
    {
        init();
        scanf("%s",str2);
        l1=strlen(str1);
        l2=strlen(str2);
        l=max(l1,l2);
        w=l1;
        e=l2;
        for(int i=0; i<l; i++)
        {
            if(l1-1>=0)
            {
                d[i]=str1[l1-1]-'0';
                l1--;
            }
            else d[i]=0;
            if(l2-1>=0)
            {
                f[i]=str2[l2-1]-'0';
                l2--;
            }
            else f[i]=0;
        }
        for(int i=0; i<w; i++)
        {
            for(int j=0; j<e; j++)
            {
                c[i+j]=c[i+j]+d[i]*f[j];
            }
        }
        for(int i=0; i<600; i++)
        {
            if(c[i]>=10)
            {
                c[i+1]+=c[i]/10;
                c[i]=c[i]%10;
            }
        }
        int flag=0;
        for(int i=600; i>=0; i--)
        {
            if(flag||c[i])
            {
                flag=1;
                printf("%d",c[i]);
            }
        }
        if(flag==0) printf("0");
        printf("\n");


    }
    return 0;
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.