大整数乘法,简洁写法

#include <bits/stdc++.h>
// #include <string>
// #include <vector>
using namespace std;

const int N = 1e5 + 10;

vector<int> multiplyLargeNumbers(const string &a, const string &b) {
    vector<int> result(a.size() + b.size(), 0);

    for (int i = 0; i < a.size(); i++) {
        int num1 = a[a.size() - 1 - i] - '0';
        for (int j = 0; j < b.size(); j++) {
            int num2 = b[b.size() - 1 - j] - '0';
            result[i + j] += num1 * num2;
            result[i + j + 1] += result[i + j] / 10;
            result[i + j] %= 10;
        }
    }

    while (result.size() > 1 && result.back() == 0) {
        result.pop_back();
    }

    reverse(result.begin(), result.end());
    return result;
}

int main() {
    string a, b;
    cin >> a >> b;

    vector<int> product = multiplyLargeNumbers(a, b);

    for (int digit : product) {
        cout << digit;
    }
    cout << endl;

    return 0;
}

列表推导式是一种简洁快速创建新列表的方式,在Python中非常常见。它的基本形式是 `[expression for item in iterable if condition]`,其中 `expression` 是对 `item` 的操作,`iterable` 是要遍历的对象,`condition` 是可选的筛选条件。例如,我们可以用列表推导式生成一个平方数列表: ```python squares = [x**2 for x in range(10)] ``` 这会生成从0到9的整数的平方列表。 NumPy是Python的一个科学计算库,它提供大量的高效数组和矩阵操作。以下是几个常用的NumPy方法: 1. **np.array()**: 将列表、元组或其他序列转换成NumPy数组。 ```python import numpy as np my_list = [1, 2, 3] arr = np.array(my_list) ``` 2. **np.arange()**: 创建一个等差数值数组,类似于range函数。 ```python linspace_arr = np.arange(0, 10, 1) # 生成0到9的均匀数组 ``` 3. **np.sum()**: 求和,用于计算数组元素总和。 ```python sum_of_elements = np.sum(arr) ``` 4. **np.mean()**: 计算平均值。 ```python mean_value = np.mean(arr) ``` 5. **np.max() and np.min()**: 找出数组的最大值和最小值。 ```python max_value = np.max(arr) min_value = np.min(arr) ``` 6. **np.reshape()**: 改变数组形状,比如把一维数组变成二维矩阵。 ```python flat_arr = arr.flatten() # 把一维数组展平 reshaped_arr = flat_arr.reshape((2, 5)) # 变成2x5矩阵 ``` 7. **np.dot() or @**: 进行矩阵乘法运算。 ```python matrix_multiply = np.dot(matrix1, matrix2) ``` 列表推导式和NumPy结合,能极大地简化数据分析和处理过程。如果你有关于NumPy的具体问题,可以在
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值