问题 C: 特殊乘法

题目描述

写个算法,对2个小于1000000000的输入,求结果。特殊乘法举例:123 * 45 = 1*4 +1*5 +2*4 +2*5 +3*4+3*5

输入

 两个小于1000000000的数

输出

 输入可能有多组数据,对于每一组数据,输出Input中的两个数按照题目要求的方法进行运算后得到的结果。

样例输入

24 65
42 66666
3 67

样例输出

66
180
39

// stdafx.h : 标准系统包含文件的包含文件,
// 或是经常使用但不常更改的
// 特定于项目的包含文件
//

#pragma once

#include “targetver.h”

#include <stdio.h>
#include <tchar.h>
#include <stdlib.h>
#include <iostream>
#include <string>
using namespace std;

// TODO: 在此处引用程序需要的其他头文件

源文件

// ProblemC.cpp: 定义控制台应用程序的入口点。
//

#include “stdafx.h”

int main()
{
string a,b;
while (cin >> a >> b) {
int len1 = a.length();
int len2 = b.length();
int result = 0;
for (int i = 0; i < len1; i++) {
for (int j = 0; j < len2; j++) {
result += (a[i]-‘0’) * (b[j]-‘0’);
}
}
cout << result << endl;
}
    return 0;

}

结果

《问题 C: 特殊乘法》

问题: 1.char类型的运算没有第一时间反应过来 要转成int ..result += (a[i]-‘0’) * (b[j]-‘0’);    

            -‘0’  很重要

    原文作者:大整数乘法问题
    原文地址: https://blog.csdn.net/youdiban9221/article/details/80692013
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞