题解 | #特殊乘法#
特殊乘法
https://www.nowcoder.com/practice/a5edebf0622045468436c74c3a34240f
#include <iostream> using namespace std; int main() { int a[10], b[10],x,y; while (cin >> x >> y) { // 注意 while 处理多个 case int i=0; while(x!=0) { a[i++]=x%10; x=x/10; } int j=0; while(y!=0) { b[j++]=y%10; y=y/10; } i--;j--; /* for(int m=0;m<=i;m++)cout<<a[m]<<" "; cout<<endl; for(int m=0;m<=j;m++)cout<<b[m]<<" "; cout<<endl; cout<<i<<" "<<j<<endl; */ int sum=0; //这样设置有个问题在于循环内部没有“统一初值”,内层循环结束后就直接结束 for(int m=i;m>=0;m--) { for(int n=j;n>=0;n--) { //cout<<sum<<endl; //cout<<i<<" "<<j<<endl; sum+=a[m]*b[n]; } } cout<<sum<<endl; } } // 64 位输出请用 printf("%lld")