题目描述

Bessie is tired of multiplying pairs of numbers the usual way, so she invented her own style of multiplication. In her style, A*B is equal to the sum of all possible pairwise products between the digits of A and B. For example, the product is equal to . Given two integers A and B (), determine  in Bessie's style of multiplication.

输入描述:

* Line 1: Two space-separated integers: A and B.

输出描述:

* Line 1: A single line that is the A*B in Bessie's style of multiplication.

示例1

输入
123 45
输出
54

解答

算是处理字符串吧!用两个数组去做,用一个数去计算它们的和即可!
 #include <algorithm>
   #include <cstring>
  #include <cstdio>
  #include <iostream>
  using namespace std;
  int main()
 {
      char a[10005],b[10005];
     int c[10005];
      while(scanf("%s%s",&a,&b)!=EOF)
     {
         memset(c,0,sizeof(c));
          int s=0;
         int lena=strlen(a);
          int lenb=strlen(b);
        for(int i=0;i<lena;i++)
        {
              for(int j=0;j<lenb;j++)
             {
                  c[i]=(int)(a[i]-'0')*(int)(b[j]-'0');
                  s+=c[i];
            }
      }
          cout<<s<<endl;
     }
      return 0;
 }


来源:angel_kitty